firstdocker / main.py
ammaan's picture
Update main.py
13d6bae verified
raw
history blame contribute delete
No virus
728 Bytes
from typing import Union
import csv
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
app = FastAPI()
def load_data(filename):
myList = []
with open(filename) as numbers:
numbers_data = csv.reader(numbers,delimiter=',')
next(numbers_data) #skip the header
for row in numbers_data:
myList.append(row)
return myList
new_list = load_data('country.csv')
@app.get("/getdata")
def getData():
return {"data": new_list}
app.mount('/',StaticFiles(directory="static",html=True),name="static")
@app.get('/')
def index() -> FileResponse:
return FileResponse('/app/static/index.html',media_type="text/html")