aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--management/commands/timetables.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py
index 279de89..c5c6dfa 100644
--- a/management/commands/timetables.py
+++ b/management/commands/timetables.py
@@ -25,7 +25,7 @@ from edt.utils import get_week
from ._private import delete_courses_in_week, get_events, get_update_date, get_weeks, get_xml
@transaction.atomic
-def process_timetable_week(timetable, soup, weeks_in_soup, year=None, week=None):
+def process_timetable_week(timetable, soup, weeks_in_soup, force, year=None, week=None):
begin, end = get_week(year, week)
last_update_date = Course.objects.filter(timetable=timetable,
@@ -35,7 +35,7 @@ def process_timetable_week(timetable, soup, weeks_in_soup, year=None, week=None)
["last_update__max"]
new_update_date = get_update_date(soup)
- if last_update_date is not None and new_update_date is not None and \
+ if not force and last_update_date is not None and new_update_date is not None and \
last_update_date >= new_update_date:
return
@@ -43,24 +43,25 @@ def process_timetable_week(timetable, soup, weeks_in_soup, year=None, week=None)
for course in get_events(timetable, soup, weeks_in_soup, year, week):
course.save()
-def process_timetable(timetable, year=None, weeks=None):
+def process_timetable(timetable, force, year=None, weeks=None):
soup = get_xml(timetable.url)
weeks_in_soup = get_weeks(soup)
if year is not None and weeks is not None:
for week in weeks:
- process_timetable_week(timetable, soup, weeks_in_soup, year, week)
+ process_timetable_week(timetable, soup, weeks_in_soup, force, year, week)
else:
- process_timetable_week(timetable, soup, weeks_in_soup)
+ process_timetable_week(timetable, soup, weeks_in_soup, force)
class Command(BaseCommand):
help = "Fetches registered celcat timetables"
def add_arguments(self, parser):
+ parser.add_argument("--all", const=True, default=False, action="store_const")
+ parser.add_argument("--force", const=True, default=False, action="store_const")
parser.add_argument("--week", type=int, choices=range(1, 54), nargs="+")
parser.add_argument("--year", type=int, nargs=1)
- parser.add_argument("--all", const=True, default=False, action="store_const")
def handle(self, *args, **options):
year = None
@@ -86,7 +87,7 @@ class Command(BaseCommand):
self.stdout.write("Processing {0}".format(timetable))
try:
- process_timetable(timetable, year, weeks)
+ process_timetable(timetable, options["force"], year, weeks)
except Exception as exc:
self.stderr.write(
self.style.ERROR("Failed to process {0}: {1}".format(timetable, exc)))