diff options
Diffstat (limited to 'management/commands/_private.py')
-rw-r--r-- | management/commands/_private.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/management/commands/_private.py b/management/commands/_private.py index f14dae6..3cd23ca 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -27,7 +27,8 @@ import requests class Week: def __init__(self, number, start): self.number = number - self.start = timezone.make_aware(datetime.datetime.strptime(start, "%d/%m/%Y")) + self.start = timezone.make_aware( + datetime.datetime.strptime(start, "%d/%m/%Y")) def get_day(self, id): return self.start + datetime.timedelta(id) @@ -45,20 +46,17 @@ def delete_courses_in_week(timetable, year, week): Course.objects.filter(begin__gte=start, begin__lt=end, timetable=timetable).delete() -def get_from_db_or_create(cls, timetable=None, **kwargs): +def get_from_db_or_create(cls, **kwargs): obj = cls.objects.all().filter(**kwargs) - if timetable is not None: - obj = obj.filter(timetable=timetable) obj = obj.first() if obj is None: obj = cls(**kwargs) - obj.timetable = timetable obj.save() return obj -def get_events(soup, weeks, year, week, timetable): +def get_events(timetable, year, week, soup, weeks_in_soup): for event in soup.find_all("event"): title = None type_ = None @@ -66,18 +64,19 @@ def get_events(soup, weeks, year, week, timetable): rooms = None notes = None - if weeks[event.rawweeks.text].number == week and \ - weeks[event.rawweeks.text].year == year and \ + if weeks_in_soup[event.rawweeks.text].number == week and \ + weeks_in_soup[event.rawweeks.text].year == year and \ event.resources.group is not None and \ event.starttime is not None and event.endtime is not None: - date = weeks[event.rawweeks.text].get_day(int(event.day.text)) + date = weeks_in_soup[event.rawweeks.text].get_day(int( + event.day.text)) begin = add_time(date, datetime.datetime.strptime( event.starttime.text, "%H:%M")) end = add_time(date, datetime.datetime.strptime( event.endtime.text, "%H:%M")) - groups = [get_from_db_or_create(Group, timetable, + groups = [get_from_db_or_create(Group, timetable=timetable, celcat_name=item.text) for item in event.resources.group.find_all("item")] @@ -104,7 +103,8 @@ def get_events(soup, weeks, year, week, timetable): def get_weeks(soup): weeks = {} for span in soup.find_all("span"): - weeks[span.alleventweeks.text] = Week(int(span.title.text), span["date"]) + weeks[span.alleventweeks.text] = Week(int(span.title.text), + span["date"]) return weeks |