diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3507a4c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.ini \ No newline at end of file diff --git a/embassy.py b/embassy.py index 69be533..3eaec92 100644 --- a/embassy.py +++ b/embassy.py @@ -1,13 +1,14 @@ # Embassy List Embassies = { - # [EMBASSY (COUNTRY CODE), FACILITY_ID (EMBASSY ID), "Continue in different languages"], - "en-am-yer": ["en-am", 122, "Continue"], # English - Armenia - YEREVAN - "es-co-bog": ["es-co", 25, "Continuar"], # Spanish - Colombia - Bogotá - "en-ca-cal": ["en-ca", 89, "Continue"], # English - Canada - Calgary - "en-ca-hal": ["en-ca", 90, "Continue"], # English - Canada - Halifax - "en-ca-mon": ["en-ca", 91, "Continue"], # English - Canada - Montreal - "en-ca-ott": ["en-ca", 92, "Continue"], # English - Canada - Ottawa - "en-ca-que": ["en-ca", 93, "Continue"], # English - Canada - Quebec City - "en-ca-tor": ["en-ca", 94, "Continue"], # English - Canada - Toronto - "en-ca-van": ["en-ca", 95, "Continue"], # English - Canada - Vancouver + # [EMBASSY (COUNTRY CODE), FACILITY_ID (EMBASSY ID), "Continue in different languages", "Success reschedule message in page", "Error reschedule message in page"], + "pt-br-poa": ["pt-br", 128, "Continuar", "Você agendou com êxito sua nomeação de visto", "Seu agendamento não pode ser realizado. Por favor, selecione uma opção válida."], # Portuguese - Brazil - Porto Alegre + "en-am-yer": ["en-am", 122, "Continue", "Successfully Scheduled", ""], # English - Armenia - YEREVAN + "es-co-bog": ["es-co", 25, "Continuar", "Successfully Scheduled", ""], # Spanish - Colombia - Bogotá + "en-ca-cal": ["en-ca", 89, "Continue", "Successfully Scheduled", ""], # English - Canada - Calgary + "en-ca-hal": ["en-ca", 90, "Continue", "Successfully Scheduled", ""], # English - Canada - Halifax + "en-ca-mon": ["en-ca", 91, "Continue", "Successfully Scheduled", ""], # English - Canada - Montreal + "en-ca-ott": ["en-ca", 92, "Continue", "Successfully Scheduled", ""], # English - Canada - Ottawa + "en-ca-que": ["en-ca", 93, "Continue", "Successfully Scheduled", ""], # English - Canada - Quebec City + "en-ca-tor": ["en-ca", 94, "Continue", "Successfully Scheduled", ""], # English - Canada - Toronto + "en-ca-van": ["en-ca", 95, "Continue", "Successfully Scheduled", ""], # English - Canada - Vancouver } diff --git a/visa.py b/visa.py index e0fda82..0d49856 100644 --- a/visa.py +++ b/visa.py @@ -35,6 +35,8 @@ EMBASSY = Embassies[YOUR_EMBASSY][0] FACILITY_ID = Embassies[YOUR_EMBASSY][1] REGEX_CONTINUE = Embassies[YOUR_EMBASSY][2] +SUCCESS_RESCHEDULE_MESSAGE = Embassies[YOUR_EMBASSY][3] +ERROR_RESCHEDULE_MESSAGE = Embassies[YOUR_EMBASSY][4] # Notification: # Get email notifications via https://sendgrid.com/ (Optional) @@ -152,11 +154,15 @@ def start_process(): auto_action("Privacy", "class", "icheckbox", "click", "", STEP_TIME) auto_action("Enter Panel", "name", "commit", "click", "", STEP_TIME) Wait(driver, 60).until(EC.presence_of_element_located((By.XPATH, "//a[contains(text(), '" + REGEX_CONTINUE + "')]"))) + # Continue to reschedule page + driver.get(APPOINTMENT_URL) + Wait(driver, 60).until(EC.presence_of_element_located((By.NAME, "commit"))) + auto_action("Continue to reschedule page", "name", "commit", "click", "", STEP_TIME) + Wait(driver, 60).until(EC.presence_of_element_located((By.ID, "appointments_submit"))) print("\n\tlogin successful!\n") def reschedule(date): time = get_time(date) - driver.get(APPOINTMENT_URL) headers = { "User-Agent": driver.execute_script("return navigator.userAgent;"), "Referer": APPOINTMENT_URL, @@ -172,12 +178,15 @@ def reschedule(date): "appointments[consulate_appointment][time]": time, } r = requests.post(APPOINTMENT_URL, headers=headers, data=data) - if(r.text.find('Successfully Scheduled') != -1): + if(r.text.find(SUCCESS_RESCHEDULE_MESSAGE) != -1): title = "SUCCESS" msg = f"Rescheduled Successfully! {date} {time}" else: title = "FAIL" - msg = f"Reschedule Failed!!! {date} {time}" + if (r.text.find(ERROR_RESCHEDULE_MESSAGE)): + msg = f"Reschedule Failed!!! {date} {time} \n Seu agendamento não pode ser realizado. Por favor, selecione uma opção válida." + else: + msg = f"Reschedule Failed!!! {date} {time} \n {r.text}" return [title, msg] @@ -210,7 +219,7 @@ def get_available_date(dates): # Evaluation of different available dates def is_in_period(date, PSD, PED): new_date = datetime.strptime(date, "%Y-%m-%d") - result = ( PED > new_date and new_date > PSD ) + result = ( PED >= new_date and new_date >= PSD ) # print(f'{new_date.date()} : {result}', end=", ") return result @@ -290,9 +299,9 @@ def info_logger(file_path, log): print(msg) info_logger(LOG_FILE_NAME, msg) time.sleep(RETRY_WAIT_TIME) - except: + except Exception as e: # Exception Occured - msg = f"Break the loop after exception!\n" + msg = f"Break the loop after exception!\n {e}" END_MSG_TITLE = "EXCEPTION" break