diff options
| -rw-r--r-- | feeds.py | 2 | ||||
| -rw-r--r-- | management/commands/_private.py | 20 | ||||
| -rw-r--r-- | management/commands/timetables.py | 19 | ||||
| -rw-r--r-- | utils.py | 6 | 
4 files changed, 27 insertions, 20 deletions
| @@ -87,7 +87,7 @@ class IcalFeed(Feed):  class RSSFeed(Feed):      def get_object(self, request, year_slug, timetable_slug, group_slug):          year, week = get_current_or_next_week() -        begin, end = get_week(year, week) +        _, end = get_week(year, week)          try:              group = Group.objects.get(timetable__year__slug=year_slug, diff --git a/management/commands/_private.py b/management/commands/_private.py index c140f51..2d01e67 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -13,15 +13,15 @@  #    You should have received a copy of the GNU Affero General Public License  #    along with celcatsanitizer.  If not, see <http://www.gnu.org/licenses/>. +import datetime +import re +  from bs4 import BeautifulSoup  from django.utils import timezone  from edt.models import Group, Room, Course  from edt.utils import get_week -import datetime -import re -  import requests @@ -31,8 +31,8 @@ class Week:          self.start = timezone.make_aware(              datetime.datetime.strptime(start, "%d/%m/%Y")) -    def get_day(self, id): -        return self.start + datetime.timedelta(id) +    def get_day(self, day_id): +        return self.start + datetime.timedelta(day_id)      @property      def year(self): @@ -75,7 +75,7 @@ def consolidate_group(group):  def consolidate_groups(groups):      for group in groups: -        if group.parent == None: +        if group.parent is None:              consolidate_group(group)  def delete_courses_in_week(timetable, year, week): @@ -153,7 +153,7 @@ def get_update_date(soup):      #                           (\d+)       au moins un nombre      #                                :      un deux-points      #                                 (\d+) au moins un nombre -    datetime_regex = re.compile("(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)") +    datetime_regex = re.compile(r"(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)")      search = datetime_regex.search(soup.footer.text)      if search is None:          return None @@ -171,8 +171,8 @@ def get_weeks(soup):      return weeks  def get_xml(url): -    r = requests.get(url) -    r.encoding = "utf8" +    req = requests.get(url) +    req.encoding = "utf8" -    soup = BeautifulSoup(r.content, "html.parser") +    soup = BeautifulSoup(req.content, "html.parser")      return soup diff --git a/management/commands/timetables.py b/management/commands/timetables.py index e136f53..f01ac3c 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -13,6 +13,8 @@  #    You should have received a copy of the GNU Affero General Public License  #    along with celcatsanitizer.  If not, see <http://www.gnu.org/licenses/>. +import datetime +  from django.core.management.base import BaseCommand  from django.db import transaction  from django.db.models import Max @@ -22,13 +24,15 @@ from edt.models import Timetable, Course  from edt.utils import get_week  from ._private import delete_courses_in_week, get_events, get_update_date, get_weeks, get_xml -import datetime -  @transaction.atomic  def process_timetable_week(timetable, year, week, soup, weeks_in_soup):      begin, end = get_week(year, week) -    last_update_date = Course.objects.filter(timetable=timetable, begin__gte=begin, begin__lt=end).aggregate(Max("last_update"))["last_update__max"] +    last_update_date = Course.objects.filter(timetable=timetable, +                                             begin__gte=begin, +                                             begin__lt=end) \ +                                     .aggregate(Max("last_update")) \ +                                     ["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 \ @@ -38,7 +42,9 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup):      delete_courses_in_week(timetable, year, week)      for name, type_, groups, rooms, notes, begin, end in \          get_events(timetable, year, week, soup, weeks_in_soup): -        course = Course.objects.create(timetable=timetable, begin=begin, end=end) +        course = Course.objects.create(timetable=timetable, +                                       begin=begin, +                                       end=end)          course.name = name          course.type = type_          course.notes = notes @@ -86,8 +92,9 @@ class Command(BaseCommand):              try:                  process_timetable(timetable, year, weeks) -            except Exception as e: -                self.stderr.write(self.style.ERROR("Failed to process {0}: {1}".format(timetable, e))) +            except Exception as exc: +                self.stderr.write( +                    self.style.ERROR("Failed to process {0}: {1}".format(timetable, exc)))                  errcount += 1          if errcount == 0: @@ -13,11 +13,11 @@  #    You should have received a copy of the GNU Affero General Public License  #    along with celcatsanitizer.  If not, see <http://www.gnu.org/licenses/>. -from django.utils import timezone -  import datetime  import re +from django.utils import timezone +  def get_current_week():      return timezone.now().isocalendar()[:2] @@ -60,7 +60,7 @@ def parse_group(name):      #                                                          \(.+\))   un ou plusieurs caractères quelconques entre parenthèses      #                                                                 ?  groupe optionnel      #                                                                  $ fin de la ligne -    group_regex = re.compile("^([\w ]+?)\s+((CM(\w))|(TD(\w)(\d))|(TP(\w)(\d)(\d)))?(\s\(.+\))?$") +    group_regex = re.compile(r"^([\w ]+?)\s+((CM(\w))|(TD(\w)(\d))|(TP(\w)(\d)(\d)))?(\s\(.+\))?$")      search = group_regex.search(name)      if search is None:          return name, None, None, None | 
