remove unused imports + add MySQL + typo error

This commit is contained in:
piair 2022-05-24 18:24:16 +02:00
parent ef469e903e
commit e98e277e8b

61
V4.py
View File

@ -3,8 +3,7 @@ import asyncio
import configparser import configparser
import os import os
from csv import reader from csv import reader
from os import path, sys, system from os import sys, system
from queue import Full
from random import choice, randint, shuffle, uniform from random import choice, randint, shuffle, uniform
from re import findall, search from re import findall, search
from sys import platform from sys import platform
@ -26,6 +25,7 @@ from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
import argparse import argparse
import mysql.connector
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -73,16 +73,20 @@ LogPath = config["PATH"]["logpath"]
#discord configurations #discord configurations
SuccessLink = config["DISCORD"]["successlink"] SuccessLink = config["DISCORD"]["successlink"]
ErrorLink = config["DISCORD"]["errorlink"] ErrorLink = config["DISCORD"]["errorlink"]
#bsae settings #base settings
FidelityLink = config["SETTINGS"]["FidelityLink"] FidelityLink = config["SETTINGS"]["FidelityLink"]
embeds = config["SETTINGS"]["embeds"] == "True" #print new point value in an embed embeds = config["SETTINGS"]["embeds"] == "True" #print new point value in an embed
Headless = config["SETTINGS"]["headless"] == "True" Headless = config["SETTINGS"]["headless"] == "True"
#proxy settings #proxy settings
proxy_enabled = config["PROXY"]["enabled"] == "True" proxy_enabled = config["PROXY"]["enabled"] == "True"
proxy_adress = config["PROXY"]["url"] proxy_adress = config["PROXY"]["url"]
proxy_port = config["PROXY"]["port"] proxy_port = config["PROXY"]["port"]
#MySQL settings
sql_enabled = config["SQL"]["enabled"] == "True"
sql_usr = config["SQL"]["usr"]
sql_pwd = config["SQL"]["pwd"]
sql_host = config["SQL"]["host"]
sql_database = config["SQL"]["database"]
g = open(MotPath, "r", encoding="utf-8") g = open(MotPath, "r", encoding="utf-8")
Liste_de_mot = list(g.readline().split(",")) Liste_de_mot = list(g.readline().split(","))
@ -99,6 +103,50 @@ def setup_proxy(ip, port) :
"proxyType": "MANUAL", "proxyType": "MANUAL",
} }
def setup_MySQL():
mydb = mysql.connector.connect(
host=sql_host,
user=sql_usr,
password=sql_pwd,
database = sql_database
)
mycursor = mydb.cursor()
def add_row(compte, points):
sql = "INSERT INTO daily (compte, points, date) VALUES (%s, %s, current_date())"
val = (compte, points)
mycursor.execute(sql, val)
mydb.commit()
printf(mycursor.rowcount, "record creatted.")
def update_row(compte, points):
sql = f"UPDATE daily SET points = {points} WHERE compte = '{compte}' AND date = current_date() ;"
mycursor.execute(sql)
mydb.commit()
printf(mycursor.rowcount, "record(s) updated")
def get_row(compte, points, same_points = True): #return if there is a line with the same ammount of point or with the same name as well as the same day
if same_points :
mycursor.execute(f"SELECT * FROM daily WHERE points = {points} AND compte = '{compte}' AND date = current_date() ;")
else :
mycursor.execute(f"SELECT * FROM daily WHERE compte = '{compte}' AND date = current_date() ;")
myresult = mycursor.fetchall()
return(len(myresult) == 1)
def add_to_database(compte, points):
if get_row(compte, points, True): #check if the row exist with the same ammount of points and do nothind if it does
printf("les points sont deja bon")
elif get_row(compte, points, False) : #check if the row exist, but without the same ammount of points and update the point account then
update_row(compte, points)
printf("row updated")
else : # if the row don't exist, create it with the good ammount of points
add_row(compte, points)
printf("row added")
def FirefoxDriver(mobile=False, Headless=Headless): def FirefoxDriver(mobile=False, Headless=Headless):
if proxy_enabled : if proxy_enabled :
@ -737,6 +785,7 @@ def TryPlay(nom="inconnu"):
def LogPoint(account="unknown"): # log des points sur discord def LogPoint(account="unknown"): # log des points sur discord
def get_points():
driver.get("https://www.bing.com/rewardsapp/flyout") driver.get("https://www.bing.com/rewardsapp/flyout")
if not IsLinux: if not IsLinux:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
@ -758,7 +807,9 @@ def LogPoint(account="unknown"): # log des points sur discord
except Exception as e: except Exception as e:
LogError(f"LogPoint - 2 - {e}") LogError(f"LogPoint - 2 - {e}")
point = "erreur" point = "erreur"
return(points)
points = get_points()
CustomSleep(uniform(3, 20)) CustomSleep(uniform(3, 20))
account = account.split("@")[0] account = account.split("@")[0]