Aggiunto supporto alla paginazione delle API
parent
70b135bb4a
commit
4e498f3c3b
|
@ -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,24 +67,41 @@ 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:
|
||||||
mp4File = file["name"]
|
nextLink = r["next"]
|
||||||
if nameFile:
|
r = session.get(f"{apiURL}&next={nextLink}").json()
|
||||||
if counter<10:
|
data.extend(r["folder"]["value"])
|
||||||
fileName = f"{nameFile} Ep 0{counter}"
|
fileCount = len(data)
|
||||||
else:
|
fileFinderDB(nameFile, rawURL, data, counter)
|
||||||
fileName = f"{nameFile} Ep {counter}"
|
print(f"Trovati {fileCount} file in totale!")
|
||||||
else:
|
|
||||||
fileName = findOneDriveLinks(file["name"])
|
|
||||||
link = f"{rawURL}{mp4File}"
|
|
||||||
counter+=1
|
|
||||||
DBSearchAndUpdate(link,fileName)
|
|
||||||
print(f"Modificati con successo {fileCount} file in totale!")
|
|
||||||
else:
|
else:
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
print(r.content)
|
print(r.content)
|
||||||
|
|
||||||
|
def fileFinderDB(nameFile, rawURL, data, counter):
|
||||||
|
for file in data:
|
||||||
|
mp4File = file["name"]
|
||||||
|
if nameFile:
|
||||||
|
if counter<10:
|
||||||
|
fileName = f"{nameFile} Ep 0{counter}"
|
||||||
|
else:
|
||||||
|
fileName = f"{nameFile} Ep {counter}"
|
||||||
|
else:
|
||||||
|
fileName = findOneDriveLinks(file["name"])
|
||||||
|
link = f"{rawURL}{mp4File}"
|
||||||
|
counter+=1
|
||||||
|
DBSearchAndUpdate(link,fileName)
|
||||||
|
|
||||||
|
def writeToText(text):
|
||||||
|
with open('link_modificati.txt', 'a', encoding='utf-8') as f:
|
||||||
|
f.write(f"{text}\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
apiOneDrive("MLIF/")
|
Loading…
Reference in New Issue