aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-09-07 19:54:03 +0200
committerAlban Gruin2017-09-07 19:54:03 +0200
commitdc272aad09f15273a930345f33943580b2a8a1f3 (patch)
tree02542476548d62a62565dc45b18d9480f458c0af
parent1561cb829a48d49d36242db89fa4490144767065 (diff)
Ajout d’un champ permettant de stocker la date de mise à jour du
calendrier celcat dans le modèle LastUpdate, ainsi que de quoi la lire depuis le XML
-rw-r--r--management/commands/_private.py25
-rw-r--r--models.py2
2 files changed, 27 insertions, 0 deletions
diff --git a/management/commands/_private.py b/management/commands/_private.py
index c31eb34..f7f8435 100644
--- a/management/commands/_private.py
+++ b/management/commands/_private.py
@@ -21,6 +21,8 @@ from edt.models import Group, Room, Course
from edt.utils import get_week
import datetime
+import re
+
import requests
@@ -122,6 +124,29 @@ def get_events(timetable, year, week, soup, weeks_in_soup):
yield title, type_, groups, rooms, notes, begin, end
+def get_update_date(soup):
+ # Explication de la regex
+ #
+ # (\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)
+ # (\d+) au moins un nombre
+ # / un slash
+ # (\d+) au moins un nombre
+ # / un slash
+ # (\d+) au moins un nombre
+ # \s+ au moins un espace
+ # (\d+) au moins un nombre
+ # : un deux-points
+ # (\d+) au moins un nombre
+ # : un deux-points
+ # (\d+) au moins un nombre
+ datetime_regex = re.compile("(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)")
+ search = datetime_regex.search(soup.footer.text)
+ if search is None:
+ return None
+
+ day, month, year, hour, minute, second = [int(v) for v in search.groups()]
+ return datetime.datetime(year, month, day, hour, minute, second)
+
def get_weeks(soup):
weeks = {}
for span in soup.find_all("span"):
diff --git a/models.py b/models.py
index 61e7f6c..01819d6 100644
--- a/models.py
+++ b/models.py
@@ -51,6 +51,8 @@ class LastUpdate(models.Model):
year = models.IntegerField(verbose_name="année")
date = models.DateTimeField(verbose_name="date de mise à jour")
+ updated_at = models.DateTimeField(verbose_name="date de publication", null=True)
+
def __str__(self):
return "{0}, semaine {1} de {2}".format(self.timetable.name, self.week, self.year)