Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data can be downloaded directly from data.gouv.fr/ #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 10 additions & 4 deletions vacances_scolaires_france/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import csv
import os
import datetime
import requests


class UnsupportedYearException(Exception):
Expand All @@ -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)
Expand Down