Bug fixing

master
MickSlash 2022-12-15 16:55:38 +00:00
parent 7c73ddaed7
commit f08875a9f0
1 changed files with 21 additions and 17 deletions

View File

@ -37,8 +37,7 @@ def replaceString(string):
def removeYearString(string): def removeYearString(string):
pattern = r"\d{4}" pattern = r"\d{4}"
str_data = re.sub(pattern, "", string) return re.sub(pattern, "", string)
return str_data
def findOneDriveLinks(str): def findOneDriveLinks(str):
@ -46,25 +45,21 @@ def findOneDriveLinks(str):
str = removeYearString(str) str = removeYearString(str)
match_str = re.findall( match_str = re.findall(
r"([a-zA-Z0-9]+)", str r"([a-zA-Z0-9]+)", str
) # In caso la stringa manipolata non dovesse dare risultati sul DB, viene suddiva in gruppi e testati fino a trovare un match )
if len(match_str)>0: if len(match_str)>0:
title = separateUpperString(match_str[0]) title = separateUpperString(match_str[0])
del(match_str[0]) del(match_str[0])
match_str = title + match_str match_str = title + match_str
new_string = "" new_string = "".join(f"{x} " for x in match_str)
for x in match_str: return new_string.rstrip()
new_string += x + " "
new_string = new_string.rstrip()
return new_string
else: else:
print(match_str) print(match_str)
def separateUpperString(str): def separateUpperString(str):
title = re.findall('[a-zA-Z][^A-Z]*', str) return re.findall('[a-zA-Z][^A-Z]*', str)
return title
def apiOneDrive(folderType=None,nameFile=None): def apiOneDrive(folderType=None,nameFile=None,epstyle=True):
apiURL = f"{LC_URL}{folderType}" apiURL = f"{LC_URL}{folderType}"
rawURL = f"{LC_FILEURL}{folderType}" rawURL = f"{LC_FILEURL}{folderType}"
counter = 1 counter = 1
@ -78,18 +73,23 @@ def apiOneDrive(folderType=None,nameFile=None):
r = session.get(f"{apiURL}&next={nextLink}").json() r = session.get(f"{apiURL}&next={nextLink}").json()
data.extend(r["folder"]["value"]) data.extend(r["folder"]["value"])
fileCount = len(data) fileCount = len(data)
fileFinderDB(nameFile, rawURL, data, counter) fileFinderDB(nameFile, rawURL, data, counter,epstyle)
print(f"Trovati {fileCount} file in totale!") print(f"Modifica provata su {fileCount} file in totale!")
mydb.close()
else: else:
print(r.status_code) print(r.status_code)
print(r.content) print(r.content)
def fileFinderDB(nameFile, rawURL, data, counter): def fileFinderDB(nameFile, rawURL, data, counter,epstyle):
for file in data: for file in data:
mp4File = file["name"] mp4File = file["name"]
if nameFile: if nameFile:
if counter<10: if counter<10 and epstyle:
fileName = f"{nameFile}E0{counter}"
elif counter < 10:
fileName = f"{nameFile} Ep 0{counter}" fileName = f"{nameFile} Ep 0{counter}"
elif counter>10 and epstyle:
fileName = f"{nameFile}E{counter}"
else: else:
fileName = f"{nameFile} Ep {counter}" fileName = f"{nameFile} Ep {counter}"
else: else:
@ -100,4 +100,8 @@ def fileFinderDB(nameFile, rawURL, data, counter):
def writeToText(text): def writeToText(text):
with open('link_modificati.txt', 'a', encoding='utf-8') as f: with open('link_modificati.txt', 'a', encoding='utf-8') as f:
f.write(f"{text}\n") f.write(f"{text}\n")
if __name__ == "__main__":
apiOneDrive("MLIF/") # Esempio