summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-03 00:55:15 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-03 00:55:15 +0100
commitfd35de8d7d67951c07c1ae5fea1e6edcfc475539 (patch)
tree1a67f4e1cea3e99e9c4b0892adf15739da50d02c
parentfmt (diff)
downloadrenfe-fd35de8d7d67951c07c1ae5fea1e6edcfc475539.tar.gz
renfe-fd35de8d7d67951c07c1ae5fea1e6edcfc475539.tar.bz2
renfe-fd35de8d7d67951c07c1ae5fea1e6edcfc475539.zip
Improvements
-rw-r--r--main.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/main.py b/main.py
index 49749b6..11f3093 100644
--- a/main.py
+++ b/main.py
@@ -30,6 +30,18 @@ def main():
 
     driver = webdriver.Chrome(options=options)
 
+    loginRenfe(driver)
+
+    navigate_to_tickets(driver)
+
+    main_loop(driver)
+
+    logging.info("TICKET BOUGHT!!")
+
+    sleep(999999999)
+
+
+def loginRenfe(driver):
     driver.get("https://venta.renfe.com/vol/loginParticular.do")
 
     sleep(5)
@@ -40,6 +52,8 @@ def main():
 
     sleep(15)
 
+
+def navigate_to_tickets(driver):
     driver.get("https://venta.renfe.com/vol/myPassesCard.do")
 
     sleep(5)
@@ -63,12 +77,20 @@ def main():
 
     sleep(5)
 
+
+def main_loop(driver):
     select_button = None
     while True:
+        # if this is not found, then we presume we have to login again
         try:
             row = driver.find_element(By.XPATH, f"//tr[td[contains(text(), '18.50')]]")
+        except Exception:
+            loginRenfe(driver)
+            navigate_to_tickets(driver)
+            continue
+        try:
             select_button = row.find_element(
-                By.XPATH, ".//button[contains(@id, 'continuar')]"
+                By.XPATH, ".//button[contains(text(), 'Seleccionar')]"
             )
             break
         except Exception:
@@ -85,8 +107,6 @@ def main():
     element = driver.find_element(By.ID, "submitSiguiente")
     driver.execute_script("arguments[0].click();", element)
 
-    logging.info("TICKET BOUGHT!!")
-
 
 if __name__ == "__main__":
     main()