aboutsummaryrefslogtreecommitdiff
path: root/management/commands/timetables.py
diff options
context:
space:
mode:
Diffstat (limited to 'management/commands/timetables.py')
-rw-r--r--management/commands/timetables.py33
1 files changed, 14 insertions, 19 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py
index 58897a1..60c9eb5 100644
--- a/management/commands/timetables.py
+++ b/management/commands/timetables.py
@@ -1,38 +1,33 @@
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone
-from edt.models import Group, Room, Course
+from edt.models import Timetable, Group, Room, Course
from bs4 import BeautifulSoup
-from ._private import get_events, get_weeks, get_xml, Week
+from ._private import delete_courses_in_week, get_events, get_weeks, get_xml, Week
import datetime
import requests
+
class Command(BaseCommand):
help = "Fetches the specified celcat timetable"
- def add_arguments(self, parser):
- parser.add_argument("url", type=str)
-
def handle(self, *args, **options):
- url = options["url"]
-
- _, week, day = timezone.now().isocalendar()
+ year, week, day = timezone.now().isocalendar()
if day >= 6:
- _, week, _ = (timezone.now() + datetime.timedelta(weeks=1)).isocalendar()
+ year, week, _ = (timezone.now() + datetime.timedelta(weeks=1)).isocalendar()
- soup = get_xml(url)
- weeks = get_weeks(soup)
+ delete_courses_in_week(year, week)
- for name, type_, groups, rooms, begin, end in get_events(soup, weeks, week):
-
- course = Course.objects.create(begin=begin, end=end)
+ for timetable in Timetable.objects.all():
+ soup = get_xml(timetable.url)
+ weeks = get_weeks(soup)
- course.name = name
- course.type = type_
- course.groups.add(*groups)
- course.rooms.add(*rooms)
- course.save()
+ for name, type_, groups, rooms, begin, end in get_events(soup, weeks, week, timetable):
+ course = Course.objects.create(name=name, type=type_, timetable=timetable, begin=begin, end=end)
+ course.groups.add(*groups)
+ course.rooms.add(*rooms)
+ course.save()
self.stdout.write(self.style.SUCCESS("Done."))