From a4000b40682c93efacec31308dce4a32eeac7ef7 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 29 Sep 2018 17:01:26 +0200 Subject: scraptimetables: adaptation de scraptimetables à la nouvelle page Signed-off-by: Alban Gruin --- management/commands/scraptimetables.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'management') diff --git a/management/commands/scraptimetables.py b/management/commands/scraptimetables.py index 1904b42..98856a5 100644 --- a/management/commands/scraptimetables.py +++ b/management/commands/scraptimetables.py @@ -15,6 +15,7 @@ from bs4 import BeautifulSoup from django.core.management.base import BaseCommand +from django.db import transaction from edt.models import Source, Timetable, Year import re @@ -27,6 +28,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument("--url", type=str, required=True) + @transaction.atomic def handle(self, *args, **options): for year, name, source in self.__get_timetables(options["url"]): source, _ = Source.objects.get_or_create(url=source) @@ -37,20 +39,24 @@ class Command(BaseCommand): req = requests.get(url) soup = BeautifulSoup(req.content, "html.parser") choose_regex = re.compile("^- Choisissez votre ([\w ]+) -$") + base_url = ("https://edt.univ-tlse3.fr/calendar/default.aspx" + "?View=month&Type=group&ResourceName=formation_") for form in soup.find_all("form"): for i, option in enumerate(form.find_all("option")): if i == 0 and option.text == "- Choisissez le niveau -": break - if "finder.html" in option["value"]: - continue search = choose_regex.search(option.text) if search is not None: current_year, _ = Year.objects.get_or_create( name=search.groups(0)[0]) else: - url = option["value"].replace("View=week", "View=month") + g = option["value"].split("-")[-1][:-5] + if g.endswith("s1"): + g = g[:-2] + + url = base_url + g.upper() if option.text.startswith(current_year.name): name = option.text[len(current_year.name):].strip() else: -- cgit v1.2.1