From aa7ccf13a8735f162e2ea859ad1d8ebe9f34f657 Mon Sep 17 00:00:00 2001
From: Alban Gruin
Date: Mon, 25 Sep 2017 16:08:01 +0200
Subject: Utilisation de pylint pour améliorer la qualité du code
---
feeds.py | 2 +-
management/commands/_private.py | 20 ++++++++++----------
management/commands/timetables.py | 19 +++++++++++++------
utils.py | 6 +++---
4 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/feeds.py b/feeds.py
index ff00066..cdecd73 100644
--- a/feeds.py
+++ b/feeds.py
@@ -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 .
+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 .
+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:
diff --git a/utils.py b/utils.py
index 3ded68e..c3b4531 100644
--- a/utils.py
+++ b/utils.py
@@ -13,11 +13,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with celcatsanitizer. If not, see .
-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
--
cgit v1.2.1