diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-12-31 18:53:34 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-12-31 18:53:34 +0100 |
commit | eba6c7912aa6098759d1e2f6c1d0f8f79882ab8e (patch) | |
tree | 09ca101dc17f81d9f69ecf73fe0b5c64fa52e3d4 /main.py | |
parent | Initial commit (diff) | |
download | renfe-eba6c7912aa6098759d1e2f6c1d0f8f79882ab8e.tar.gz renfe-eba6c7912aa6098759d1e2f6c1d0f8f79882ab8e.tar.bz2 renfe-eba6c7912aa6098759d1e2f6c1d0f8f79882ab8e.zip |
fmt
Diffstat (limited to '')
-rw-r--r-- | main.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/main.py b/main.py index d1e1bff..49749b6 100644 --- a/main.py +++ b/main.py @@ -6,35 +6,36 @@ import logging import os from dotenv import load_dotenv + def main(): logging.basicConfig( - format='%(asctime)s %(levelname)-8s %(message)s', + format="%(asctime)s %(levelname)-8s %(message)s", level=logging.INFO, - datefmt='%Y-%m-%d %H:%M:%S' + datefmt="%Y-%m-%d %H:%M:%S", ) load_dotenv() - test_ua = 'Mozilla/5.0 (Windows NT 4.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36' + test_ua = "Mozilla/5.0 (Windows NT 4.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36" options = Options() # options.add_argument("--headless") # Remove this if you want to see the browser (Headless makes the chromedriver not have a GUI) # options.add_argument("--window-size=1920,1080") - options.add_argument(f'--user-agent={test_ua}') + options.add_argument(f"--user-agent={test_ua}") - options.add_argument('--no-sandbox') + options.add_argument("--no-sandbox") options.add_argument("--disable-extensions") driver = webdriver.Chrome(options=options) - driver.get('https://venta.renfe.com/vol/loginParticular.do') + driver.get("https://venta.renfe.com/vol/loginParticular.do") sleep(5) - driver.find_element(By.ID, "num_tarjeta").send_keys(os.getenv('RENFE_EMAIL')) - driver.find_element(By.ID, "pass-login").send_keys(os.getenv('RENFE_PASSWORD')) + driver.find_element(By.ID, "num_tarjeta").send_keys(os.getenv("RENFE_EMAIL")) + driver.find_element(By.ID, "pass-login").send_keys(os.getenv("RENFE_PASSWORD")) driver.find_element(By.ID, "loginButtonId").click() sleep(15) @@ -50,7 +51,7 @@ def main(): sleep(5) - #todo: select radio button ida o vuelta + # todo: select radio button ida o vuelta datepicker = driver.find_element(By.ID, "fecha1") driver.execute_script(f"arguments[0].value = '06/01/2025';", datepicker) @@ -66,7 +67,9 @@ def main(): while True: try: row = driver.find_element(By.XPATH, f"//tr[td[contains(text(), '18.50')]]") - select_button = row.find_element(By.XPATH, ".//button[contains(@id, 'continuar')]") + select_button = row.find_element( + By.XPATH, ".//button[contains(@id, 'continuar')]" + ) break except Exception: logging.info("No available places - refreshing...") @@ -84,5 +87,6 @@ def main(): logging.info("TICKET BOUGHT!!") + if __name__ == "__main__": main() |