From 6b5ce7082d283ff1ae9561eef87b6cb512ad68d8 Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 13 Jun 2022 11:14:13 +0200 Subject: [PATCH 1/5] Data can be downloaded directly from from https://www.data.gouv.fr/fr/datasets/r/c3781037-dffb-4789-9af9-15a955336771 --- vacances_scolaires_france/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vacances_scolaires_france/__init__.py b/vacances_scolaires_france/__init__.py index 8221db8..92dc28a 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: bool = False, file: str = 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: bool = False, file: str = 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) From a329bf540367edbd7556827f559cfb6f035912bd Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 13 Jun 2022 11:28:35 +0200 Subject: [PATCH 2/5] Removed type hint in mathod signatures --- vacances_scolaires_france/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vacances_scolaires_france/__init__.py b/vacances_scolaires_france/__init__.py index 92dc28a..78c7ca3 100644 --- a/vacances_scolaires_france/__init__.py +++ b/vacances_scolaires_france/__init__.py @@ -30,12 +30,12 @@ class SchoolHolidayDates(object): 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, download: bool = False, file: str = None): + def __init__(self, download=False, file=None): super(SchoolHolidayDates, self).__init__() self.data = {} self.load_data(download, file) - def load_data(self, download: bool = False, file: str = None): + 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) From e87addfe0a495c18a405a761b9b8c52440d9584e Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 13 Jun 2022 11:34:50 +0200 Subject: [PATCH 3/5] Added 'request' to requirements --- setup.py | 1 + 1 file changed, 1 insertion(+) 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", From 33475df9f526d6e66ffdcfe6c2f5485680041e77 Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 13 Jun 2022 11:41:14 +0200 Subject: [PATCH 4/5] added: import collections collections.Callable = collections.abc.Callable --- vacances_scolaires_france/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vacances_scolaires_france/__init__.py b/vacances_scolaires_france/__init__.py index 78c7ca3..57de17e 100644 --- a/vacances_scolaires_france/__init__.py +++ b/vacances_scolaires_france/__init__.py @@ -3,6 +3,8 @@ import os import datetime import requests +import collections +collections.Callable = collections.abc.Callable class UnsupportedYearException(Exception): From b9e05b659b004b3ab8b75be4832e13b4015cb9d2 Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 13 Jun 2022 11:42:40 +0200 Subject: [PATCH 5/5] Revert "added: import collections" This reverts commit 33475df9f526d6e66ffdcfe6c2f5485680041e77. --- vacances_scolaires_france/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/vacances_scolaires_france/__init__.py b/vacances_scolaires_france/__init__.py index 57de17e..78c7ca3 100644 --- a/vacances_scolaires_france/__init__.py +++ b/vacances_scolaires_france/__init__.py @@ -3,8 +3,6 @@ import os import datetime import requests -import collections -collections.Callable = collections.abc.Callable class UnsupportedYearException(Exception):