fbuetler / asvz-bot

ASVZ Bot to enroll to lessons. Get a place when the registration opens or when a place gets free. Works for ETH, UZH and ZHAW students.
GNU General Public License v3.0
66 stars 25 forks source link

list index out of range #15

Closed Glanfaloth closed 1 year ago

Glanfaloth commented 1 year ago

Hi the script was running fine before but when a spot becomes free I got this

2023-01-17 10:01:25 INFO     Lesson has free places
Traceback (most recent call last):
  File "/local/home/asvz-bot/src/asvz_bot.py", line 606, in <module>
    main()
  File "/local/home/asvz-bot/src/asvz_bot.py", line 602, in main
    enroller.enroll()
  File "/local/home/asvz-bot/src/asvz_bot.py", line 289, in enroll
    self.__organisation_login(driver)
  File "/local/home/asvz-bot/src/asvz_bot.py", line 383, in __organisation_login
    WebDriverWait(driver, 20).until(
  File "/local/home/asvz-bot/src/.venv/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
#0 0x55c8c92a2303 <unknown>
#1 0x55c8c9076d37 <unknown>
#2 0x55c8c90b35b2 <unknown>
#3 0x55c8c90b36c1 <unknown>
#4 0x55c8c90edb34 <unknown>
#5 0x55c8c90d39ad <unknown>
#6 0x55c8c90eb88c <unknown>
#7 0x55c8c90d3753 <unknown>
#8 0x55c8c90a6a14 <unknown>
#9 0x55c8c90a7b7e <unknown>
#10 0x55c8c92f132e <unknown>
#11 0x55c8c92f4c0e <unknown>
#12 0x55c8c92d7610 <unknown>
#13 0x55c8c92f5c23 <unknown>
#14 0x55c8c92c9545 <unknown>
#15 0x55c8c93166a8 <unknown>
#16 0x55c8c9316836 <unknown>
#17 0x55c8c9331d13 <unknown>
#18 0x7f98955d0609 start_thread

Then when I tried to run it again, I couldn't anymore. Could you help? Thank you!

Traceback (most recent call last):
  File "/local/home/asvz-bot/src/asvz_bot.py", line 606, in <module>
    main()
  File "/local/home/asvz-bot/src/asvz_bot.py", line 587, in main
    enroller = AsvzEnroller(chromedriver, lesson_url, creds)
  File "/local/home/asvz-bot/src/asvz_bot.py", line 253, in __init__
    self.__get_enrollment_and_start_time()
  File "/local/home/asvz-bot/src/asvz_bot.py", line 338, in __get_enrollment_and_start_time
    enrollment_interval_raw.get_attribute("innerHTML")
IndexError: list index out of range
fbuetler commented 1 year ago

Hm, looks like the ASVZ website has been updated and the format of "Einschreibezeitraum" has changed. Previously, it was <day start>, <date start> <time start> - <day end>, <date end> <time end> (like So, 09.05.2021 06:35 - Mo, 10.05.2021 07:05), but now only has <date start> - <date end> (like 17.01.2023 - 17.01.2023). I am not sure if this is intended, as now the time is missing, but obviously breaks the "parsing":

            enrollment_interval_raw = driver.find_element(
                By.XPATH, "//dl[contains(., 'Einschreibezeitraum')]/dd"
            )

            enrollment_start_raw = (
                enrollment_interval_raw.get_attribute("innerHTML")
                .split("-")[0]
                .split(",")[1]
                .strip()
            )

I am not sure what to do here. With "insider knowledge" the script can assume a 24h registration window prior to the course. But this is then just a heuristic. I noticed that there is now an introduction text at the top of the lesson with the registration window, maybe this can be used.

Glanfaloth commented 1 year ago

Thank you for the quick reply! I just hard coded the enrollment_start_raw. But now I have trouble logging in...

2023-01-17 11:35:09 INFO     Checking login credentials
Traceback (most recent call last):
  File "/Users/Downloads/asvz-bot/src/asvz_bot.py", line 603, in <module>
    main()
  File "/Users/Downloads/asvz-bot/src/asvz_bot.py", line 599, in main
    enroller.enroll()
  File "/Users/Downloads/asvz-bot/src/asvz_bot.py", line 261, in enroll
    self.__organisation_login(driver)
  File "/Users/Downloads/asvz-bot/src/asvz_bot.py", line 380, in __organisation_login
    WebDriverWait(driver, 20).until(
  File "/Users/Downloads/asvz-bot/src/.venv/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
0   chromedriver                        0x0000000100608fa8 chromedriver + 4886440
1   chromedriver                        0x0000000100586643 chromedriver + 4351555
2   chromedriver                        0x00000001001d4b27 chromedriver + 477991
3   chromedriver                        0x000000010021976c chromedriver + 759660
4   chromedriver                        0x00000001002199c1 chromedriver + 760257
5   chromedriver                        0x000000010025d204 chromedriver + 1036804
6   chromedriver                        0x000000010023f5fd chromedriver + 914941
7   chromedriver                        0x000000010025a5fe chromedriver + 1025534
8   chromedriver                        0x000000010023f3a3 chromedriver + 914339
9   chromedriver                        0x000000010020957f chromedriver + 693631
10  chromedriver                        0x000000010020ab1e chromedriver + 699166
11  chromedriver                        0x00000001005d5b9e chromedriver + 4676510
12  chromedriver                        0x00000001005da91e chromedriver + 4696350
13  chromedriver                        0x00000001005e219f chromedriver + 4727199
14  chromedriver                        0x00000001005db81a chromedriver + 4700186
15  chromedriver                        0x00000001005aea62 chromedriver + 4516450
16  chromedriver                        0x00000001005fa8c8 chromedriver + 4827336
17  chromedriver                        0x00000001005faa45 chromedriver + 4827717
18  chromedriver                        0x00000001006107ef chromedriver + 4917231
19  libsystem_pthread.dylib             0x00007ff80b917259 _pthread_start + 125
20  libsystem_pthread.dylib             0x00007ff80b912c7b thread_start + 15

What do you think could be the reason?

fbuetler commented 1 year ago

Apparently, they also changed the class of the login button from class="btn btn-default ng-star-inserted" to class="btn btn-default" and this breaks the bot as well:

        logging.debug("Start login process")
        WebDriverWait(driver, 20).until(
            EC.element_to_be_clickable(
                (
                    By.XPATH,
                    "//button[@class='btn btn-default ng-star-inserted' and @title='Login']",
                )
            )
        ).click()

This is fixed on the master branch.

Glanfaloth commented 1 year ago

Thank you very much! There is another problem, a lesson that has already been booked out shows "Lesson has free places" and "Waiting for enrollment", then 5min later "Place was already taken in the meantime. Rechecking for available places."

Is it possible that there has been some change to ausgebucht check as well? I think it is the same issue as before, the ng-star-inserted was also removed for the alert

Glanfaloth commented 1 year ago

changing "//alert[@class='ng-star-inserted'][contains(., 'ausgebucht')]", to "//div[@class='alert alert-warning'][contains(., 'ausgebucht')]", works now!! You might also want to remove ng-star-inserted in register button

fbuetler commented 1 year ago

Yes, I noticed that in the meantime as well, and I hope I accommodated the script for all the relevant changes. Let me know if you encounter any issues with the master branch. Otherwise, I am going to tag it with a new version in the next couple of days.