Sousmargot/backend/src/months.py

29 lines
726 B
Python

from pathlib import Path
import csv
CSV_STYLE = {
"delimiter": ",",
"quotechar": '"',
}
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 = []
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(path:str):
month_files = list_month_files(path)
months = []
for file in month_files:
months += extract_month(file)
return months