hotfix, but a nice one
This commit is contained in:
parent
67aad7921f
commit
4814dfed46
32
V5.py
32
V5.py
|
@ -248,9 +248,9 @@ def all_cards():
|
|||
liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
|
||||
try :
|
||||
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
|
||||
except :
|
||||
log_error(f"IndexError, need more log\ncurrent index : {i} \nmaximal index : {len(liste)}", driver)
|
||||
return("INDEX ERROR")
|
||||
except IndexError :
|
||||
if i == len(liste) & i > 15 :
|
||||
checked = False
|
||||
if checked:
|
||||
custom_sleep(1.5)
|
||||
driver.execute_script("arguments[0].scrollIntoView();", liste[i])
|
||||
|
@ -275,7 +275,17 @@ def all_cards():
|
|||
try_play(driver.title)
|
||||
close_tab(driver.window_handles[1])
|
||||
if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")):
|
||||
driver.execute_script("arguments[0].scrollIntoView();", liste[i])
|
||||
log_error(f"Card {i} Can't be completed. Why MS ?", driver)
|
||||
liste[i].click()
|
||||
driver.switch_to.window(driver.window_handles[1])
|
||||
log_error(f"Cart completion - log - 2", driver)
|
||||
custom_sleep(10)
|
||||
log_error(f"Cart completion - log - 3 - after 10 sec", driver)
|
||||
try:
|
||||
try_play(driver.title) # go back to the main page
|
||||
except :
|
||||
driver.get("https://rewards.bing.com")
|
||||
except :
|
||||
pass
|
||||
else :
|
||||
|
@ -288,17 +298,20 @@ def all_cards():
|
|||
|
||||
|
||||
def promo():
|
||||
elm = driver.find_element(By.ID, "promo-item")
|
||||
for i in range(10):
|
||||
elm = driver.find_element(By.ID, "promo-item")
|
||||
wait_until_visible(By.ID, "promo-item", 5, driver)
|
||||
if not elm:
|
||||
break
|
||||
if i > 8 :
|
||||
log_error("chelou, plus de 8 truc", driver)
|
||||
try :
|
||||
elm.click()
|
||||
except :
|
||||
except Exception as e:
|
||||
#log_error(e, driver)
|
||||
driver.execute_script("arguments[0].click();", elm)
|
||||
printf("that should't be there (promo)")
|
||||
#log_error(e, driver)
|
||||
printf(f"that should't be there (promo), but the workarround seemed to work {e}")
|
||||
custom_sleep(3)
|
||||
if len(driver.window_handles) > 1 :
|
||||
driver.switch_to.window(driver.window_handles[len(driver.window_handles)-1])
|
||||
|
@ -345,6 +358,11 @@ def try_play(nom="inconnu"):
|
|||
else:
|
||||
printf("There is an error. rqAnswerOption present in page but no action to do. skipping.")
|
||||
|
||||
if "pas connecté à Microsoft Rewards" in driver.page_source:
|
||||
driver.find_element(By.CSS_SELECTOR, '[onclick="setsrchusr()"]').click()
|
||||
custom_sleep(5)
|
||||
printf("not connected, fixed")
|
||||
|
||||
try:
|
||||
if wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
|
||||
custom_sleep(3)
|
||||
|
@ -445,7 +463,7 @@ def login_part_2(ldriver, cookies = False):
|
|||
except Exception as e:
|
||||
pass
|
||||
wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 20, ldriver)
|
||||
ldriver.get("https://www.bing.com/?setlang=fr&cc=fr&cc=FR")
|
||||
ldriver.get("https://www.bing.com/")
|
||||
rgpd_popup(ldriver)
|
||||
ldriver.refresh()
|
||||
rgpd_popup(ldriver)
|
||||
|
|
|
@ -3,7 +3,8 @@ from modules.config import *
|
|||
from modules.tools import *
|
||||
import modules.globals as g
|
||||
|
||||
def setup_proxy(ip, port) :
|
||||
|
||||
def setup_proxy(ip: str, port: str) -> None:
|
||||
PROXY = f"{ip}:{port}"
|
||||
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
|
||||
"httpProxy": PROXY,
|
||||
|
@ -11,7 +12,8 @@ def setup_proxy(ip, port) :
|
|||
"proxyType": "MANUAL",
|
||||
}
|
||||
|
||||
#Deal with rgpd popup as well as some random popup like 'are you satisfied' one
|
||||
|
||||
#Deal with RGPD popup as well as some random popup like 'are you satisfied' one
|
||||
def rgpd_popup(driver) -> None:
|
||||
for i in ["bnp_btn_accept", "bnp_hfly_cta2", "bnp_hfly_close"] :
|
||||
try:
|
||||
|
@ -19,8 +21,9 @@ def rgpd_popup(driver) -> None:
|
|||
except:
|
||||
pass
|
||||
|
||||
|
||||
# save webdriver cookies
|
||||
def save_cookies(driver):
|
||||
def save_cookies(driver) -> None:
|
||||
if g.dev:
|
||||
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "w")
|
||||
for i in driver.get_cookies():
|
||||
|
@ -29,8 +32,9 @@ def save_cookies(driver):
|
|||
else :
|
||||
pickle.dump(driver.get_cookies(), open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}.pkl", "wb"))
|
||||
|
||||
|
||||
# load cookies previously saved to the driver
|
||||
def load_cookies(driver):
|
||||
def load_cookies(driver) -> None:
|
||||
if g.dev:
|
||||
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "r")
|
||||
lines = f.readlines()
|
||||
|
@ -45,7 +49,7 @@ def load_cookies(driver):
|
|||
send_keys_wait([selenium element:element, str:keys]) send the different keys to the field element, with a random time between each press to simulate human action.
|
||||
keys can be an string, but also selenium keys
|
||||
"""
|
||||
def send_keys_wait(element, keys):
|
||||
def send_keys_wait(element, keys: str) -> None:
|
||||
for i in keys:
|
||||
element.send_keys(i)
|
||||
sleep(uniform(0.1, 0.3))
|
||||
|
@ -58,6 +62,6 @@ def wait_until_visible(search_by: str, identifier: str, timeout = 20, browser =
|
|||
WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((search_by,identifier)), "element not found")
|
||||
return(True)
|
||||
except TimeoutException as e:
|
||||
printf(f"element not found after {timeout}s")
|
||||
printf(f"element {identifier} not found after {timeout}s")
|
||||
return(False)
|
||||
|
||||
|
|
Loading…
Reference in New Issue