aboutsummaryrefslogtreecommitdiff
path: root/management/commands/scraptimetables.py
diff options
context:
space:
mode:
authorAlban Gruin2018-09-29 17:01:26 +0200
committerAlban Gruin2018-09-29 17:01:26 +0200
commita4000b40682c93efacec31308dce4a32eeac7ef7 (patch)
tree2b0a9587fd5f7f55beb770f826f9f1e6c0b4eee3 /management/commands/scraptimetables.py
parent3c8f53e8657ebc3bd2229ffe67f944d19d38d0b5 (diff)
scraptimetables: adaptation de scraptimetables à la nouvelle page
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
Diffstat (limited to 'management/commands/scraptimetables.py')
-rw-r--r--management/commands/scraptimetables.py12
1 files changed, 9 insertions, 3 deletions
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: