Merge pull request #11 from augustin64/patch-2
This commit is contained in:
commit
ca0ae8917a
18
V4.py
18
V4.py
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3.10
|
||||
import asyncio
|
||||
from csv import reader
|
||||
import csv
|
||||
from os import sys, system, path
|
||||
from random import choice, randint, shuffle, uniform
|
||||
from re import findall, search
|
||||
|
@ -907,7 +907,19 @@ def unban2():
|
|||
except Banned :
|
||||
unban()
|
||||
except NotBanned :
|
||||
printf("you are not cureently banned on this account")
|
||||
printf("you are not currently banned on this account")
|
||||
|
||||
def SavePointsFromFile(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 StartTask(task):
|
||||
|
@ -939,6 +951,8 @@ if CUSTOM_START:
|
|||
CustomStart(Credentials)
|
||||
elif UNBAN:
|
||||
unban2()
|
||||
elif POINTS_FILE != "":
|
||||
SavePointsFromFile(POINTS_FILE)
|
||||
else:
|
||||
|
||||
with Progress(
|
||||
|
|
|
@ -64,6 +64,14 @@ parser.add_argument(
|
|||
type=argparse.FileType('r')
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-a",
|
||||
"--add-points",
|
||||
help="Add points to the database from a file and exit",
|
||||
dest="points_file",
|
||||
default=""
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
CUSTOM_START = args.override
|
||||
UNBAN = args.unban
|
||||
|
@ -73,7 +81,9 @@ FAST = args.fast
|
|||
if CUSTOM_START :
|
||||
LOG = True
|
||||
|
||||
# gloabal variables used later in the code
|
||||
POINTS_FILE = args.points_file
|
||||
|
||||
# global variables used later in the code
|
||||
LINUX_HOST = platform == "linux" # if the computer running this programm is linux, it allow more things
|
||||
START_TIME = time()
|
||||
driver = None
|
||||
|
@ -145,4 +155,4 @@ g.close()
|
|||
with open(CREDENTIALS_PATH) as f:
|
||||
reader = reader(f)
|
||||
Credentials = list(reader)
|
||||
shuffle(Credentials)
|
||||
shuffle(Credentials)
|
||||
|
|
|
@ -32,30 +32,36 @@ def get_row(compte, points, mycursor, same_points = True): #return if there is a
|
|||
return(len(myresult) == 1)
|
||||
|
||||
|
||||
def add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database ):
|
||||
mydb = mysql.connector.connect(
|
||||
host=sql_host,
|
||||
user=sql_usr,
|
||||
password=sql_pwd,
|
||||
database = sql_database
|
||||
)
|
||||
mycursor = mydb.cursor()
|
||||
def add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database, save_if_fail=True):
|
||||
try:
|
||||
mydb = mysql.connector.connect(
|
||||
host=sql_host,
|
||||
user=sql_usr,
|
||||
password=sql_pwd,
|
||||
database = sql_database
|
||||
)
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
if get_row(compte, points,mycursor, True): #check if the row exist with the same ammount of points and do nothind if it does
|
||||
#printf("les points sont deja bon")
|
||||
#return(0)
|
||||
pass
|
||||
elif get_row(compte, points,mycursor, False) : #check if the row exist, but without the same ammount of points and update the point account then
|
||||
update_row(compte, points,mycursor,mydb)
|
||||
#printf("row updated")
|
||||
#return(1)
|
||||
else : # if the row don't exist, create it with the good ammount of points
|
||||
add_row(compte, points,mycursor,mydb)
|
||||
#return(2) #printf("row added")
|
||||
if int(points) > 10 :
|
||||
update_last(compte, points, mycursor, mydb)
|
||||
|
||||
mycursor.close()
|
||||
mydb.close()
|
||||
if get_row(compte, points,mycursor, True): #check if the row exist with the same ammount of points and do nothind if it does
|
||||
#printf("les points sont deja bon")
|
||||
#return(0)
|
||||
pass
|
||||
elif get_row(compte, points,mycursor, False) : #check if the row exist, but without the same ammount of points and update the point account then
|
||||
update_row(compte, points,mycursor,mydb)
|
||||
#printf("row updated")
|
||||
#return(1)
|
||||
else : # if the row don't exist, create it with the good ammount of points
|
||||
add_row(compte, points,mycursor,mydb)
|
||||
#return(2) #printf("row added")
|
||||
if int(points) > 10 :
|
||||
update_last(compte, points, mycursor, mydb)
|
||||
|
||||
mycursor.close()
|
||||
mydb.close()
|
||||
except BaseException as e:
|
||||
if save_if_fail:
|
||||
print("\nLes points n'ont pas pu être ajoutés, enregistrement dans le fichier 'points.csv'\n")
|
||||
with open("points.csv", "a") as file:
|
||||
file.write(f"{compte},{points}\n")
|
||||
raise e
|
||||
|
||||
|
|
Loading…
Reference in New Issue