Aggiunto supporto alla paginazione delle API
parent
70b135bb4a
commit
4e498f3c3b
|
@ -16,18 +16,18 @@ mydb = mysql.connector.connect(
|
|||
)
|
||||
|
||||
def DBSearchAndUpdate(link,value):
|
||||
mycursor = mydb.cursor()
|
||||
# sql = "SELECT * FROM `tbl_episode` WHERE titolo LIKE %s"
|
||||
sql = "UPDATE tbl_episode SET `link embedded` = %s WHERE titolo LIKE %s"
|
||||
mycursor = mydb.cursor(buffered=True)
|
||||
sql = "UPDATE tbl_episode SET `link embedded` = %s WHERE `titolo` LIKE %s LIMIT 1"
|
||||
val = (f'{link}',f'%{value}%')
|
||||
mycursor.execute(sql,val)
|
||||
myresult = mycursor.fetchone()
|
||||
print(myresult)
|
||||
print(f"{mycursor.rowcount} - {value} - {link}")
|
||||
if mycursor.rowcount == 1:
|
||||
print(myresult)
|
||||
text = f"Modificato : {value}"
|
||||
writeToText(text)
|
||||
mydb.commit()
|
||||
else:
|
||||
print("Impossibile trovare il file desiderato!")
|
||||
text = f"Non Modificato : {value}"
|
||||
writeToText(text)
|
||||
|
||||
|
||||
def replaceString(string):
|
||||
|
@ -55,7 +55,6 @@ def findOneDriveLinks(str):
|
|||
for x in match_str:
|
||||
new_string += x + " "
|
||||
new_string = new_string.rstrip()
|
||||
print(new_string)
|
||||
return new_string
|
||||
else:
|
||||
print(match_str)
|
||||
|
@ -68,12 +67,25 @@ def separateUpperString(str):
|
|||
def apiOneDrive(folderType=None,nameFile=None):
|
||||
apiURL = f"{LC_URL}{folderType}"
|
||||
rawURL = f"{LC_FILEURL}{folderType}"
|
||||
counter = 1
|
||||
r = session.get(apiURL)
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
counter = 1
|
||||
fileCount = len(data["folder"]["value"])
|
||||
for file in data["folder"]["value"]:
|
||||
r = r.json()
|
||||
data = r["folder"]["value"]
|
||||
if r["next"]:
|
||||
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"]
|
||||
if nameFile:
|
||||
if counter<10:
|
||||
|
@ -85,7 +97,11 @@ def apiOneDrive(folderType=None,nameFile=None):
|
|||
link = f"{rawURL}{mp4File}"
|
||||
counter+=1
|
||||
DBSearchAndUpdate(link,fileName)
|
||||
print(f"Modificati con successo {fileCount} file in totale!")
|
||||
else:
|
||||
print(r.status_code)
|
||||
print(r.content)
|
||||
|
||||
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