File size: 728 Bytes
549d2af
3390ce8
549d2af
72f4984
 
549d2af
 
3390ce8
 
 
 
 
 
 
 
 
 
 
 
72f4984
 
 
13d6bae
72f4984
 
 
 
 
 
 
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
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")