diff options
author | Alban Gruin | 2018-08-25 23:01:31 +0200 |
---|---|---|
committer | Alban Gruin | 2018-09-03 19:19:54 +0200 |
commit | 77b6ade4a7d465ca0fbc6b82950f3b54689d60e3 (patch) | |
tree | 120fe20233fb3a506e5c1ae30bf57645a7f1ca22 /management | |
parent | e7f2ccdd870f998b9199b85bf2c486f8d1d0cceb (diff) |
parsers: déplacement de delete_courses_in_week() vers timetable.py
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
Diffstat (limited to 'management')
-rw-r--r-- | management/commands/timetables.py | 12 | ||||
-rw-r--r-- | management/parsers/ups2017.py | 9 |
2 files changed, 10 insertions, 11 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 8fc8ed6..c148fed 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -23,8 +23,14 @@ from django.db.models import Min from ...models import Course, Source from ...utils import get_week, tz_now -from ..parsers.ups2017 import delete_courses_in_week, get_events, \ - get_update_date, get_weeks, get_xml +from ..parsers.ups2017 import get_events, get_update_date, get_weeks, \ + get_source + + +def delete_courses_in_week(source, year, week, today): + start, end = get_week(year, week) + Course.objects.filter(begin__gte=max(start, today), begin__lt=end, + source=source).delete() @transaction.atomic @@ -100,7 +106,7 @@ def process_timetable_week(source, soup, weeks_in_soup, force, def process_timetable(source, force, year=None, weeks=None): - soup = get_xml(source.url) + soup = get_source(source.url) weeks_in_soup = get_weeks(soup) if year is not None and weeks is not None: diff --git a/management/parsers/ups2017.py b/management/parsers/ups2017.py index 94c1918..8522793 100644 --- a/management/parsers/ups2017.py +++ b/management/parsers/ups2017.py @@ -20,7 +20,6 @@ from bs4 import BeautifulSoup from django.utils import timezone from ...models import Course, Group, Room -from ...utils import get_week import requests import edt @@ -32,12 +31,6 @@ def add_time(date, time): return date + delta -def delete_courses_in_week(source, year, week, today): - start, end = get_week(year, week) - Course.objects.filter(begin__gte=max(start, today), begin__lt=end, - source=source).delete() - - def get_event(source, event, event_week, today): """Renvoie une classe Course à partir d’un événement récupéré par BS4""" # On récupère la date de l’évènement à partir de la semaine @@ -155,7 +148,7 @@ def get_weeks(soup): return weeks -def get_xml(url): +def get_source(url): user_agent = "celcatsanitizer/" + edt.VERSION req = requests.get(url, headers={"User-Agent": user_agent}) req.encoding = "utf8" |