2023-03-27 22:20:54 +02:00
|
|
|
from modules.imports import *
|
2022-10-24 20:08:33 +02:00
|
|
|
from modules.config import *
|
2023-04-12 18:25:12 +02:00
|
|
|
import modules.globals as g
|
2022-10-24 20:08:33 +02:00
|
|
|
|
2023-03-12 11:22:49 +01:00
|
|
|
# add the time arround the text given in [text]&
|
2023-04-12 18:25:12 +02:00
|
|
|
def Timer(text: str) -> str:
|
|
|
|
return(f"[{g._mail.split('@')[0]} - {datetime.today().strftime('%d/%m')} - {timedelta(seconds = round(float(time() - START_TIME)))}] " + str(text))
|
2022-10-24 20:08:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
# replace the function print, with more options
|
2023-04-02 11:02:37 +02:00
|
|
|
# [txt] : string, [driver] : selenium webdriver
|
2023-04-12 18:25:12 +02:00
|
|
|
def printf(txt):
|
|
|
|
print(Timer(txt))
|
2022-10-24 20:08:33 +02:00
|
|
|
|
|
|
|
|
2023-04-12 18:25:12 +02:00
|
|
|
# return current page domain
|
|
|
|
def get_domain(driver):
|
|
|
|
return(driver.current_url.split("/")[2])
|
2022-10-24 20:08:33 +02:00
|
|
|
|
2023-04-12 18:25:12 +02:00
|
|
|
|
2022-10-24 20:08:33 +02:00
|
|
|
# check if the user is using IPV4 using ipify.org
|
|
|
|
# [driver] : selenium webdriver
|
2023-03-14 19:54:12 +01:00
|
|
|
# never used here
|
2023-04-02 11:02:37 +02:00
|
|
|
# can be useful as Ms had issues with IPV6 at some point
|
2022-10-24 20:08:33 +02:00
|
|
|
def check_ipv4(driver):
|
|
|
|
driver.get("https://api64.ipify.org")
|
2023-03-12 11:22:49 +01:00
|
|
|
elm = driver.find_element(By.TAG_NAME, "body")
|
2022-10-24 20:08:33 +02:00
|
|
|
if len(elm.text.split('.')) == 4 :
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2023-04-02 11:02:37 +02:00
|
|
|
def custom_sleep(temps):
|
2022-10-25 19:44:33 +02:00
|
|
|
try :
|
|
|
|
if FAST and temps > 50:
|
|
|
|
sleep(temps/10)
|
2023-04-02 11:02:37 +02:00
|
|
|
elif LOG: #only print sleep when user see it
|
2022-10-25 19:44:33 +02:00
|
|
|
points = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
|
|
|
|
passe = 0
|
|
|
|
for i in range(int(temps)):
|
|
|
|
for i in range(8):
|
|
|
|
sleep(0.125)
|
|
|
|
passe += 0.125
|
|
|
|
print(f"{points[i]} - {round(float(temps) - passe, 3)}", end="\r")
|
|
|
|
print(" ", end="\r")
|
|
|
|
else:
|
|
|
|
sleep(temps)
|
|
|
|
except KeyboardInterrupt :
|
2022-11-06 13:37:12 +01:00
|
|
|
print("attente annulée")
|
2022-10-25 19:44:33 +02:00
|
|
|
|
|
|
|
|
2023-04-02 11:02:37 +02:00
|
|
|
def format_error(e) -> str:
|
2023-03-14 19:54:12 +01:00
|
|
|
tb = e.__traceback__
|
|
|
|
txt = ""
|
|
|
|
while tb != None :
|
2023-04-02 12:32:21 +02:00
|
|
|
txt = txt + f" -> {tb.tb_frame.f_code.co_name} ({tb.tb_lineno}) "
|
2023-03-14 19:54:12 +01:00
|
|
|
tb = tb.tb_next
|
2023-04-02 11:02:37 +02:00
|
|
|
return(txt + "\n" + str(e))
|
2022-10-25 19:44:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
def progressBar(current, total=30, barLength=20, name="Progress"):
|
|
|
|
percent = float(current + 1) * 100 / total
|
|
|
|
arrow = "-" * int(percent / 100 * barLength - 1) + ">"
|
|
|
|
spaces = " " * (barLength - len(arrow))
|
|
|
|
print(name + ": [%s%s] %d %%" % (arrow, spaces, percent), end="\r")
|
2023-03-27 22:20:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def save_points_from_file(file):
|
|
|
|
with open(file) as f:
|
|
|
|
reader = csv.reader(f)
|
|
|
|
points_list = list(reader)
|
|
|
|
|
|
|
|
for item in points_list:
|
|
|
|
compte, points = item[0], item[1]
|
|
|
|
add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database, save_if_fail=False)
|
|
|
|
|
|
|
|
with open(file, "w") as f:
|
|
|
|
f.write("")
|
|
|
|
|
|
|
|
|
|
|
|
def select_accounts(multiple = True):
|
|
|
|
system("clear") # clear from previous command to allow a clean choice
|
|
|
|
emails = [x[0] for x in Credentials] # list of all email adresses
|
|
|
|
emails_selected = enquiries.choose(f"quel{'s' if multiple else ''} compte{'s' if multiple else ''} ?", emails, multi=multiple)
|
|
|
|
return([x for x in Credentials if x[0] in emails_selected])
|
|
|
|
|