Feat(back): retreive_months
This commit is contained in:
parent
eb97abee7f
commit
7ab8df0f24
0
backend/src/__init__.py
Normal file
0
backend/src/__init__.py
Normal file
@ -1,10 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from ..config import config
|
||||
from ..months import retreive_months
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/months")
|
||||
async def get_months():
|
||||
print(config)
|
||||
return {"message": "plop"}
|
||||
return retreive_months()
|
||||
|
28
backend/src/months.py
Normal file
28
backend/src/months.py
Normal file
@ -0,0 +1,28 @@
|
||||
from .config import config
|
||||
from pathlib import Path
|
||||
import csv
|
||||
|
||||
CSV_STYLE = {
|
||||
"delimiter": ",",
|
||||
"quotechar": '"',
|
||||
}
|
||||
|
||||
def list_month_files(file_schema:str="*_months.csv") -> list[Path]:
|
||||
return list(Path(config["datapath"]).glob(file_schema))
|
||||
|
||||
def extract_month(filename:Path) -> list[dict[str,str]]:
|
||||
months = []
|
||||
with open(filename, 'r', newline='') as csvfile:
|
||||
month_reader = csv.DictReader(csvfile, **CSV_STYLE)
|
||||
for month in month_reader:
|
||||
months.append(month)
|
||||
return months
|
||||
|
||||
|
||||
|
||||
def retreive_months():
|
||||
month_files = list_month_files()
|
||||
months = []
|
||||
for file in month_files:
|
||||
months += extract_month(file)
|
||||
return months
|
Loading…
Reference in New Issue
Block a user