jarvisx17 commited on
Commit
a8cf3d1
1 Parent(s): 7aea15d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +39 -0
main.py CHANGED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi.responses import HTMLResponse
2
+ from fastapi.templating import Jinja2Templates
3
+ from fastapi import FastAPI, Request, HTTPException
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+
6
+ app = FastAPI()
7
+
8
+ origins = ["*"]
9
+
10
+ app.add_middleware(
11
+ CORSMiddleware,
12
+ allow_origins=origins,
13
+ allow_credentials=True,
14
+ allow_methods=["*"],
15
+ allow_headers=["*"],
16
+ )
17
+
18
+ templates = Jinja2Templates(directory="templates")
19
+
20
+ @app.get("/", response_class=HTMLResponse)
21
+ async def read_root(request: Request):
22
+ return templates.TemplateResponse("hello.html", {"request": request})
23
+
24
+
25
+ @app.get('/data')
26
+ async def get_data(ticker: str, date: str, qty: int):
27
+ try:
28
+ response = "Bye"
29
+ return response
30
+ except:
31
+ return {"Timeout" : "Error"}
32
+
33
+ @app.get('/stocks')
34
+ async def get_stocks_data():
35
+ try:
36
+ response = "Hello"
37
+ return response
38
+ except:
39
+ return {"Timeout" : "Error"}