-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
42 lines (34 loc) · 908 Bytes
/
Copy pathserver.py
File metadata and controls
42 lines (34 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from typing import Union
import csv
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from fastapi import FastAPI
from typing import List, Dict
app = FastAPI()
origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/get_data", response_model=List[Dict[str,str]])
def read_item():
sender = []
with open('spam_rankings.csv', newline='') as csvfile:
# Create a reader object
csv_reader = csv.DictReader(csvfile)
for i in csv_reader:
sender.append(i)
return sender
if __name__ =="__main__":
uvicorn.run(app,host="localhost", port=8080)