diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index afddc50..7319fbf 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -20,10 +20,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: v0.0.2a - release_name: v0.0.2a + tag_name: v0.0.3 + release_name: v0.0.3 body: | - Adding DESIRED_DATE as environment variable + logout_from_website() method added draft: false prerelease: false diff --git a/.gitignore b/.gitignore index ed8ebf5..398c41e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -__pycache__ \ No newline at end of file +__pycache__ +Pipfile \ No newline at end of file diff --git a/__version__.py b/__version__.py index 5ebf923..8dbfdad 100644 --- a/__version__.py +++ b/__version__.py @@ -1 +1 @@ -__version__ = '0.0.2a' \ No newline at end of file +__version__ = '0.0.3' \ No newline at end of file diff --git a/main.py b/main.py index 046180f..6ebf0d6 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ IDENTIFICATION, PASSWORD, HEADQUARTER_NAME, + DESIRED_DATE, DESIRED_TIME, WHATSAPP_URL, CHAT_NAME, @@ -15,10 +16,10 @@ from smartfit_booking.website_bot import ( initialize, login_to_website, - answer_questionnaire, search_headquarter, book_hour, get_qr_code, + logout_from_website, login_to_whatsapp, search_chat, send_message @@ -37,10 +38,10 @@ def main(): """ book_an_hour """ driver = initialize(DRIVER_PATH, OUTPUT_PATH, CHROME_PROFILE_PATH) login_to_website(driver, WEBSITE_URL, IDENTIFICATION, PASSWORD) - answer_questionnaire(driver) search_headquarter(driver, HEADQUARTER_NAME) - book_hour(driver, DESIRED_TIME) + book_hour(driver, DESIRED_DATE, DESIRED_TIME) qr_code_url = get_qr_code(driver) + logout_from_website(driver) """ download_qr_code """ response = get_data(qr_code_url) @@ -50,7 +51,7 @@ def main(): """ send_whatsapp_message """ login_to_whatsapp(driver, WHATSAPP_URL) search_chat(driver, CHAT_NAME) - send_message(driver, image_path, PERSON_NAME, DESIRED_TIME) + send_message(driver, image_path, PERSON_NAME, DESIRED_DATE, DESIRED_TIME) remove_file(image_path) if __name__ == '__main__': diff --git a/secrets.py b/secrets.py index f6ef3e2..1274578 100644 --- a/secrets.py +++ b/secrets.py @@ -25,6 +25,7 @@ IDENTIFICATION = os.environ.get('IDENTIFICATION') PASSWORD = os.environ.get('PASSWORD') HEADQUARTER_NAME = os.environ.get('HEADQUARTER_NAME') +DESIRED_DATE = os.environ.get('DESIRED_DATE') DESIRED_TIME = os.environ.get('DESIRED_TIME') WHATSAPP_URL = os.environ.get('WHATSAPP_URL') CHAT_NAME = os.environ.get('CHAT_NAME') diff --git a/smartfit_booking/website_bot.py b/smartfit_booking/website_bot.py index af0bae7..8d2bfd7 100644 --- a/smartfit_booking/website_bot.py +++ b/smartfit_booking/website_bot.py @@ -124,6 +124,18 @@ def get_qr_code(driver: object) -> str: driver.quit() raise +def logout_from_website(driver: object) -> None: + try: + logout_button = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.XPATH, '//button[@aria-label="logout"]')) + ) + logout_button.click() + time.sleep(10) + logger.info('Logout from website has been successfully') + except Exception as error: + logger.error(f'Error to logout from website: {error}') + raise + def login_to_whatsapp(driver: object, whatsapp_url: str) -> None: try: driver.get(whatsapp_url) # Already authenticated @@ -135,7 +147,7 @@ def login_to_whatsapp(driver: object, whatsapp_url: str) -> None: def search_chat(driver: object, chat_name: str) -> None: try: - search_box = WebDriverWait(driver, 10).until( + search_box = WebDriverWait(driver, 500).until( EC.presence_of_element_located((By.XPATH, '//div[@contenteditable="true"][@data-tab="3"]')) ) search_box.clear()