-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_init.py
106 lines (70 loc) · 3.29 KB
/
main_init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import time
import pandas as pd
from bs4 import BeautifulSoup
import chromedriver_autoinstaller
import os
import subprocess
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
def insert_text(id, text, wait):
#email_textbox = driver.find_element(By.ID, id)
textbox = wait.until(EC.presence_of_element_located((By.ID, id)))
textbox.send_keys(text)
textbox.click()
#textbox.send_keys(text)
return textbox
def initial_exec(user, pwd, website, gui_option=False):
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--search-engine-choice-country')
if not gui_option:
chrome_options.add_argument('--headless')
#chrome_options.add_argument("--headless")
#webdriver_service = Service(chromedriver)
#webdriver_service = Service()
# Create a WebDriver instance
driver = webdriver.Chrome(options=chrome_options)
driver.get(website)
wait = WebDriverWait(driver, 10)
# input email
insert_text('email', user, wait)
# input pwd
insert_text('password', pwd, wait)
validate_login = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-cy="login-button"]')))
validate_login.click()
new_reservation = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-cy="booknew-button"]')))
new_reservation.click()
# First, check if we have the correct gym selected, otherwise we have to remove it and add the correct one
gym_name = 'Arco do Cego'
#element = wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(), '{}')]".format(gym_name))))
#print(element.text)
# when Miguel is the user then deselect picoas gym and select only arco do cego
if 'miguel' in user:
option_to_select = wait.until(EC.presence_of_element_located((By.XPATH, '//li[@role="option"]//span[text()="{}"]'.format(gym_name))))
driver.execute_script("arguments[0].click();", option_to_select)
# deselect the wrong one
bad_gym_name = 'Picoas'
option_to_deselect = wait.until(EC.presence_of_element_located((By.XPATH, '//li[@role="option"]//span[text()="{}"]'.format(bad_gym_name))))
driver.execute_script("arguments[0].click();", option_to_deselect)
else:
pass
return driver, wait
# github cloning and push commits
def clone_repo(repo_url, clone_dir=''):
if not os.path.exists(clone_dir):
subprocess.run(['git', 'clone', repo_url, clone_dir])
def commit_push(commit_message, repo_dir=None):
# Add and commit the changes
subprocess.run(['git', 'add', '.'], cwd=repo_dir)
subprocess.run(['git', 'commit', '-m', commit_message], cwd=repo_dir)
# Push the changes back to GitHub
subprocess.run(['git', 'push'], cwd=repo_dir)