aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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