aboutsummaryrefslogtreecommitdiff
path: root/management/commands/_private.py
diff options
context:
space:
mode:
authorAlban Gruin2017-02-28 13:30:03 +0100
committerAlban Gruin2017-02-28 13:30:03 +0100
commitce0ed9347adde9ca80c11efe79766c966d5749ba (patch)
treee371a2d06374efbad1c1c8a4558d92ee0a07c025 /management/commands/_private.py
parenta543aaa14957f390d2b640a264113b639c7d3194 (diff)
parent66be6f2e7a3c642fb3c69e7c2a70cc3f898d77ea (diff)
Merge branch 'stable/0.y.z' into prod/pa1ch/0.y.zv0.7.0-pa1ch
Diffstat (limited to 'management/commands/_private.py')
-rw-r--r--management/commands/_private.py22
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