aboutsummaryrefslogtreecommitdiff
path: root/management
diff options
context:
space:
mode:
authorAlban Gruin2017-09-09 19:38:02 +0200
committerAlban Gruin2017-09-09 19:38:02 +0200
commit35613677472450a066967795cad63f8f70c2bcc4 (patch)
tree6740723219a179878438e8ac2671d89a1a0709a2 /management
parent373a20aa44620db4032e64a2a781afd2f558efb4 (diff)
Création des objets Year lorsqu’ils sont rencontrés
Diffstat (limited to 'management')
-rw-r--r--management/commands/scraptimetables.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/management/commands/scraptimetables.py b/management/commands/scraptimetables.py
index cb5753d..4a07b3b 100644
--- a/management/commands/scraptimetables.py
+++ b/management/commands/scraptimetables.py
@@ -14,7 +14,8 @@
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
from django.core.management.base import BaseCommand
-from ._private import get_xml
+from edt.models import Timetable, Year
+from ._private import get_from_db_or_create, get_xml
import re
@@ -26,7 +27,14 @@ class Command(BaseCommand):
parser.add_argument("--url", type=str, required=True)
def handle(self, *args, **options):
- url = options["url"]
+ timetables = {}
+ for year, name, finder in self.__get_finders(options["url"]):
+ if year in timetables:
+ timetables[year].append((name, finder,))
+ else:
+ timetables[year] = [(name, finder,)]
+
+ def __get_finders(self, url):
soup = get_xml(url)
choose_regex = re.compile("^- Choisissez votre ([\w ]+) -$")
@@ -37,7 +45,12 @@ class Command(BaseCommand):
search = choose_regex.search(option.text)
if search is not None:
- print()
- print("Groupe :", search.groups(0)[0])
+ current_year = get_from_db_or_create(Year, name=search.groups(0)[0])
else:
- print(option.text, option["value"])
+ finder = option["value"].replace("finder", "finder2")
+ if option.text.startswith(current_year.name):
+ name = option.text[len(current_year.name):].strip()
+ else:
+ name = option.text
+
+ yield current_year, name, finder