hotfix, but a nice one

This commit is contained in:
piair 2023-05-30 20:21:25 +02:00
parent 67aad7921f
commit 4814dfed46
3 changed files with 37 additions and 15 deletions

34
V5.py
View File

@ -248,9 +248,9 @@ def all_cards():
liste = driver.find_elements(By.CLASS_NAME, "c-card-content") liste = driver.find_elements(By.CLASS_NAME, "c-card-content")
try : try :
checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")) checked = ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML"))
except : except IndexError :
log_error(f"IndexError, need more log\ncurrent index : {i} \nmaximal index : {len(liste)}", driver) if i == len(liste) & i > 15 :
return("INDEX ERROR") checked = False
if checked: if checked:
custom_sleep(1.5) custom_sleep(1.5)
driver.execute_script("arguments[0].scrollIntoView();", liste[i]) driver.execute_script("arguments[0].scrollIntoView();", liste[i])
@ -275,7 +275,17 @@ def all_cards():
try_play(driver.title) try_play(driver.title)
close_tab(driver.window_handles[1]) close_tab(driver.window_handles[1])
if ("mee-icon-AddMedium" in liste[i].get_attribute("innerHTML")): 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) 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 : except :
pass pass
else : else :
@ -288,17 +298,20 @@ def all_cards():
def promo(): def promo():
elm = driver.find_element(By.ID, "promo-item")
for i in range(10): 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: if not elm:
break break
if i > 8 : if i > 8 :
log_error("chelou, plus de 8 truc", driver) log_error("chelou, plus de 8 truc", driver)
try : try :
elm.click() elm.click()
except : except Exception as e:
#log_error(e, driver)
driver.execute_script("arguments[0].click();", elm) 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) custom_sleep(3)
if len(driver.window_handles) > 1 : if len(driver.window_handles) > 1 :
driver.switch_to.window(driver.window_handles[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: else:
printf("There is an error. rqAnswerOption present in page but no action to do. skipping.") 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: try:
if wait_until_visible(By.ID, "rqStartQuiz", 5, driver): if wait_until_visible(By.ID, "rqStartQuiz", 5, driver):
custom_sleep(3) custom_sleep(3)
@ -352,7 +370,7 @@ def try_play(nom="inconnu"):
answer_number = driver.page_source.count("rqAnswerOption") answer_number = driver.page_source.count("rqAnswerOption")
play(answer_number) play(answer_number)
else : else :
raise (NameError("going to next part")) raise(NameError("going to next part"))
except Exception as e: # if there is no start button, an error is thrown except Exception as e: # if there is no start button, an error is thrown
if "bt_PollRadio" in driver.page_source: if "bt_PollRadio" in driver.page_source:
try: try:
@ -445,7 +463,7 @@ def login_part_2(ldriver, cookies = False):
except Exception as e: except Exception as e:
pass pass
wait_until_visible(By.CSS_SELECTOR, '[data-bi-id="sh-sharedshell-home"]', 20, ldriver) 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) rgpd_popup(ldriver)
ldriver.refresh() ldriver.refresh()
rgpd_popup(ldriver) rgpd_popup(ldriver)

View File

@ -3,7 +3,8 @@ from modules.config import *
from modules.tools import * from modules.tools import *
import modules.globals as g import modules.globals as g
def setup_proxy(ip, port) :
def setup_proxy(ip: str, port: str) -> None:
PROXY = f"{ip}:{port}" PROXY = f"{ip}:{port}"
webdriver.DesiredCapabilities.FIREFOX['proxy'] = { webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
"httpProxy": PROXY, "httpProxy": PROXY,
@ -11,7 +12,8 @@ def setup_proxy(ip, port) :
"proxyType": "MANUAL", "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: def rgpd_popup(driver) -> None:
for i in ["bnp_btn_accept", "bnp_hfly_cta2", "bnp_hfly_close"] : for i in ["bnp_btn_accept", "bnp_hfly_cta2", "bnp_hfly_close"] :
try: try:
@ -19,8 +21,9 @@ def rgpd_popup(driver) -> None:
except: except:
pass pass
# save webdriver cookies # save webdriver cookies
def save_cookies(driver): def save_cookies(driver) -> None:
if g.dev: if g.dev:
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "w") f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "w")
for i in driver.get_cookies(): for i in driver.get_cookies():
@ -29,8 +32,9 @@ def save_cookies(driver):
else : else :
pickle.dump(driver.get_cookies(), open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}.pkl", "wb")) 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 # load cookies previously saved to the driver
def load_cookies(driver): def load_cookies(driver) -> None:
if g.dev: if g.dev:
f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "r") f = open(f"{'/'.join(__file__.split('/')[:-2])}/user_data/cookies/{g._mail}_unsafe.pkl", "r")
lines = f.readlines() 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. 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 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: for i in keys:
element.send_keys(i) element.send_keys(i)
sleep(uniform(0.1, 0.3)) 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") WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((search_by,identifier)), "element not found")
return(True) return(True)
except TimeoutException as e: except TimeoutException as e:
printf(f"element not found after {timeout}s") printf(f"element {identifier} not found after {timeout}s")
return(False) return(False)

View File

@ -1 +1 @@
v5.10.9 v5.10.10