Aggiunto supporto alla paginazione delle API

master
MickSlash 2022-12-14 22:11:41 +00:00
parent 70b135bb4a
commit 4e498f3c3b
1 changed files with 107 additions and 91 deletions

View File

@ -16,18 +16,18 @@ mydb = mysql.connector.connect(
) )
def DBSearchAndUpdate(link,value): def DBSearchAndUpdate(link,value):
mycursor = mydb.cursor() mycursor = mydb.cursor(buffered=True)
# sql = "SELECT * FROM `tbl_episode` WHERE titolo LIKE %s" sql = "UPDATE tbl_episode SET `link embedded` = %s WHERE `titolo` LIKE %s LIMIT 1"
sql = "UPDATE tbl_episode SET `link embedded` = %s WHERE titolo LIKE %s"
val = (f'{link}',f'%{value}%') val = (f'{link}',f'%{value}%')
mycursor.execute(sql,val) mycursor.execute(sql,val)
myresult = mycursor.fetchone() print(f"{mycursor.rowcount} - {value} - {link}")
print(myresult)
if mycursor.rowcount == 1: if mycursor.rowcount == 1:
print(myresult) text = f"Modificato : {value}"
writeToText(text)
mydb.commit() mydb.commit()
else: else:
print("Impossibile trovare il file desiderato!") text = f"Non Modificato : {value}"
writeToText(text)
def replaceString(string): def replaceString(string):
@ -55,7 +55,6 @@ def findOneDriveLinks(str):
for x in match_str: for x in match_str:
new_string += x + " " new_string += x + " "
new_string = new_string.rstrip() new_string = new_string.rstrip()
print(new_string)
return new_string return new_string
else: else:
print(match_str) print(match_str)
@ -68,12 +67,25 @@ def separateUpperString(str):
def apiOneDrive(folderType=None,nameFile=None): def apiOneDrive(folderType=None,nameFile=None):
apiURL = f"{LC_URL}{folderType}" apiURL = f"{LC_URL}{folderType}"
rawURL = f"{LC_FILEURL}{folderType}" rawURL = f"{LC_FILEURL}{folderType}"
counter = 1
r = session.get(apiURL) r = session.get(apiURL)
if r.status_code == 200: if r.status_code == 200:
data = r.json() r = r.json()
counter = 1 data = r["folder"]["value"]
fileCount = len(data["folder"]["value"]) if r["next"]:
for file in data["folder"]["value"]: while "next" in r:
nextLink = r["next"]
r = session.get(f"{apiURL}&next={nextLink}").json()
data.extend(r["folder"]["value"])
fileCount = len(data)
fileFinderDB(nameFile, rawURL, data, counter)
print(f"Trovati {fileCount} file in totale!")
else:
print(r.status_code)
print(r.content)
def fileFinderDB(nameFile, rawURL, data, counter):
for file in data:
mp4File = file["name"] mp4File = file["name"]
if nameFile: if nameFile:
if counter<10: if counter<10:
@ -85,7 +97,11 @@ def apiOneDrive(folderType=None,nameFile=None):
link = f"{rawURL}{mp4File}" link = f"{rawURL}{mp4File}"
counter+=1 counter+=1
DBSearchAndUpdate(link,fileName) DBSearchAndUpdate(link,fileName)
print(f"Modificati con successo {fileCount} file in totale!")
else: def writeToText(text):
print(r.status_code) with open('link_modificati.txt', 'a', encoding='utf-8') as f:
print(r.content) f.write(f"{text}\n")
apiOneDrive("MLIF/")