Feat(all): back and front communicate
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from ..months import retreive_months
|
||||
from ..config import config
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:8080"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@app.get("/months")
|
||||
async def get_months():
|
||||
return retreive_months()
|
||||
return retreive_months(config["datapath"])
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from .config import config
|
||||
from pathlib import Path
|
||||
import csv
|
||||
|
||||
@@ -7,8 +6,9 @@ CSV_STYLE = {
|
||||
"quotechar": '"',
|
||||
}
|
||||
|
||||
def list_month_files(file_schema:str="*_months.csv") -> list[Path]:
|
||||
return list(Path(config["datapath"]).glob(file_schema))
|
||||
def list_month_files(path:str, file_schema:str="*_months.csv") -> list[Path]:
|
||||
print(list(Path(path).glob("*")))
|
||||
return list(Path(path).glob(file_schema))
|
||||
|
||||
def extract_month(filename:Path) -> list[dict[str,str]]:
|
||||
months = []
|
||||
@@ -20,8 +20,8 @@ def extract_month(filename:Path) -> list[dict[str,str]]:
|
||||
|
||||
|
||||
|
||||
def retreive_months():
|
||||
month_files = list_month_files()
|
||||
def retreive_months(path:str):
|
||||
month_files = list_month_files(path)
|
||||
months = []
|
||||
for file in month_files:
|
||||
months += extract_month(file)
|
||||
|
||||
Reference in New Issue
Block a user