diff --git a/setup.py b/setup.py index d4109d2..48604f1 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ "holiday", "calendar", ], + install_requires=['requests'], extras_require={"dev": ["nose"]}, package_data={"vacances_scolaires_france": ["data/data.csv"]}, python_requires=">=2.7, <4", diff --git a/vacances_scolaires_france/__init__.py b/vacances_scolaires_france/__init__.py index 8221db8..78c7ca3 100644 --- a/vacances_scolaires_france/__init__.py +++ b/vacances_scolaires_france/__init__.py @@ -2,6 +2,7 @@ import csv import os import datetime +import requests class UnsupportedYearException(Exception): @@ -26,14 +27,19 @@ class SchoolHolidayDates(object): "Vacances de la Toussaint", "Pont de l'Ascension", ] + STABLE_URL = "https://www.data.gouv.fr/fr/datasets/r/c3781037-dffb-4789-9af9-15a955336771" + BASE_FILE = os.path.join(os.path.dirname(__file__), "data/data.csv") - def __init__(self): + def __init__(self, download=False, file=None): super(SchoolHolidayDates, self).__init__() self.data = {} - self.load_data() + self.load_data(download, file) - def load_data(self): - filename = os.path.join(os.path.dirname(__file__), "data/data.csv") + def load_data(self, download=False, file=None): + if download: + r = requests.get(SchoolHolidayDates.STABLE_URL, allow_redirects=True) + open(file, 'wb').write(r.content) + filename = file if file and os.path.isfile(file) else SchoolHolidayDates.BASE_FILE with open(filename) as f: reader = csv.DictReader(f)