diff options
author | Alban Gruin | 2017-01-19 13:51:46 +0100 |
---|---|---|
committer | Alban Gruin | 2017-01-19 13:51:46 +0100 |
commit | e9d4b61b1fb0d5efa78df56a2529185d3d8fabf5 (patch) | |
tree | 23e5bc9abdfdcf1e4db9b9d6f6c7635715a87b4d /management/commands/timetables.py | |
parent | 7855fc164a16e0303f3d9aa7ee5c2ee9c719b4de (diff) |
Association des cours et groupes à des emplois du temps spécifiques
Diffstat (limited to 'management/commands/timetables.py')
-rw-r--r-- | management/commands/timetables.py | 33 |
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.")) |