mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-15 17:28:46 +00:00
Changing string concatenation to .format(). Other small fixes.
This commit is contained in:
parent
841d567c78
commit
07d3f1f960
28
actions.py
28
actions.py
@ -11,6 +11,8 @@ from checks import checkTimestamp
|
||||
from checks import checkStatus
|
||||
from checks import getToken
|
||||
|
||||
# TODO add counters for number of images downloaded and deleted
|
||||
|
||||
def wait():
|
||||
input("Press enter to continue.")
|
||||
|
||||
@ -71,28 +73,30 @@ def clearLogin():
|
||||
|
||||
def clearFolders(): # TODO implement this
|
||||
folders = ["banner", "fanart", "poster"]
|
||||
del_count = 0
|
||||
for folder in folders:
|
||||
if os.path.exists(folder):
|
||||
imageList = os.listdir(folder)
|
||||
if len(imageList) != 0:
|
||||
print("Clearing " + folder + "/")
|
||||
for x in imageList: # TODO check if folder is empty
|
||||
print("Deleting " + x)
|
||||
print("Deleting {}/{}".format(folder, x))
|
||||
delPath = os.path.join(folder + "\\" + x)
|
||||
os.remove(delPath)
|
||||
del_count += 1
|
||||
print()
|
||||
else:
|
||||
print("'" + folder + "'" + " is already empty")
|
||||
print("'{}' is already empty".format(folder))
|
||||
else:
|
||||
createFolder(folder)
|
||||
print("")
|
||||
print("Deleted {} images.\n".format(del_count))
|
||||
|
||||
def createFolder(folder): # TODO remove this
|
||||
os.makedirs(folder)
|
||||
|
||||
|
||||
def searchImages(idNum, keyType, authHeaders): # This is getting a list of file info for images in json format
|
||||
queryUrl = "https://api.thetvdb.com/series/" + str(idNum) + "/images/query" + keyType # TODO change this to string formatting
|
||||
queryUrl = "https://api.thetvdb.com/series/{}/images/query{}".format(str(idNum), keyType)
|
||||
response = requests.get(queryUrl, headers=authHeaders)
|
||||
if (checkStatus(response, True)):
|
||||
return response
|
||||
@ -120,7 +124,7 @@ def searchRemainder(imageType, saveNameList, idNum):#Finds any images missing fr
|
||||
filenum = hyphenSuffix.replace(".jpg", "")
|
||||
numbers.append(int(filenum))
|
||||
else:
|
||||
print("I couldn't find a hyphen in: %s" % name) # Error checking
|
||||
print("I couldn't find a hyphen in: {}".format(name)) # Error checking
|
||||
numbers.sort
|
||||
missingList = findMissing(numbers)
|
||||
minNum = min(numbers)
|
||||
@ -139,16 +143,16 @@ def tryMissing(missingNums, minNum, maxNum, idNum, imageType):
|
||||
startDirectory = "posters/"
|
||||
|
||||
for num in missingNums:
|
||||
fileName = startDirectory + str(idNum) + "-" + str(num) + ".jpg"
|
||||
fileName = "{}{}-{}.jpg".format(startDirectory, str(idNum), str(num))
|
||||
# fileName = "%s%s-%d.jpg" % startDirectory, idNum, missingNums[num]
|
||||
# try:
|
||||
print("Trying... " + fileName)
|
||||
dlUrl = "https://www.thetvdb.com/banners/" + fileName
|
||||
print("Trying... {}".format(fileName))
|
||||
dlUrl = "https://www.thetvdb.com/banners/{}".format(fileName)
|
||||
# print("url is: " + dlUrl)
|
||||
response = requests.get(dlUrl)
|
||||
# print(response.status_code)
|
||||
if (checkStatus(response, True) == True): # TODO there is an error occurring here when checking fanart
|
||||
path = os.path.join(imageType + "\\" + str(idNum) + "-" + str(num) + ".jpg") # TODO string formatting
|
||||
path = os.path.join("{}\\{}-{}.jpg".format(imageType, str(idNum), str(num)))
|
||||
obj = open(path, "wb")
|
||||
obj.write(response.content)
|
||||
obj.close()
|
||||
@ -176,8 +180,8 @@ def download(imageType, parsed_respObj):
|
||||
saveName = fileName[slashIndex + 1:] # For example 'https://thetvdb.com/banners/fanart/original/32451-3.jpg' --> '32451.jpg'
|
||||
saveNameList.append(saveName)
|
||||
|
||||
print("Downloading... " + fileName)
|
||||
dlUrl = "https://www.thetvdb.com/banners/" + fileName
|
||||
print("Downloading... {}".format(fileName))
|
||||
dlUrl = "https://www.thetvdb.com/banners/{}".format(fileName)
|
||||
response = requests.get(dlUrl) # TODO getting errors when checking 'new game'. Check to see if those images actually exist
|
||||
|
||||
if (checkStatus(response, True)):
|
||||
@ -210,7 +214,7 @@ def update():
|
||||
"https://github.com/ClaytonWWilson/Image-fetcher-for-theTVDB.com")
|
||||
return
|
||||
if code == 0:
|
||||
print("\nThe program has been updated.\n")
|
||||
print("\nUpdating complete.\n")
|
||||
else:
|
||||
print("\nThere was an error while updating. This may be caused by edits "
|
||||
"you have made to the code.")
|
||||
|
||||
@ -25,7 +25,7 @@ def checkStatus(response, v):
|
||||
if (response.status_code != 200):
|
||||
if (v == True):
|
||||
print("\nAn error occurred.")
|
||||
print("HTTP Code: " + str(response.status_code))
|
||||
print("HTTP Code: {}".format(str(response.status_code)))
|
||||
# error = json.loads(response.content) # TODO move this somewhere else
|
||||
# print("Response : " + error["Error"])
|
||||
return False
|
||||
|
||||
18
launcher.py
18
launcher.py
@ -23,9 +23,9 @@ while True:
|
||||
print("1. Search theTVDB.com")
|
||||
print("2. Clear download folders")
|
||||
print("3. Login/Change login")
|
||||
print("4. Refresh API Token")
|
||||
print("5. Install Requirements")
|
||||
print("6. Check for updates\n")
|
||||
# print("4. Refresh API Token")
|
||||
print("4. Install Requirements")
|
||||
print("5. Check for updates\n")
|
||||
print("0. Exit\n")
|
||||
|
||||
choice = user_choice()
|
||||
@ -42,14 +42,14 @@ while True:
|
||||
clearLogin()
|
||||
login()
|
||||
wait()
|
||||
elif choice == "4": # TODO need to perform this option automatically
|
||||
clear_screen()
|
||||
refreshToken()
|
||||
wait()
|
||||
elif choice == "5":
|
||||
# elif choice == "4": # TODO need to perform this option automatically
|
||||
# clear_screen()
|
||||
# refreshToken()
|
||||
# wait()
|
||||
elif choice == "4":
|
||||
print("install requirements not implemented yet")
|
||||
wait()
|
||||
elif choice == "6":
|
||||
elif choice == "5":
|
||||
update()
|
||||
wait()
|
||||
elif choice == "0":
|
||||
|
||||
2
login.py
2
login.py
@ -57,7 +57,7 @@ def login():
|
||||
obj.close()
|
||||
print("\nLogin successful!\n")
|
||||
else:# if login.json already exists
|
||||
with open("login.json") as json_data:# TODO add a check for a login that is damaged/modified
|
||||
with open("login.json") as json_data:# TODO add a check for a login file that is damaged/modified
|
||||
login = json.load(json_data)
|
||||
json_data.close()
|
||||
saveTime = dateutil.parser.parse(login["TIMESTAMP"])
|
||||
|
||||
@ -57,7 +57,7 @@ def search():
|
||||
sKeyword = sKeyword.replace("/", "%2F")
|
||||
sKeyword = sKeyword.replace("%7E", "~")
|
||||
|
||||
searchUrl = "https://api.thetvdb.com/search/series?name=" + sKeyword
|
||||
searchUrl = "https://api.thetvdb.com/search/series?name={}".format(sKeyword)
|
||||
response = requests.get(searchUrl, headers=authHeaders)
|
||||
|
||||
if (checkStatus(response, True) == False):
|
||||
@ -72,11 +72,11 @@ def search():
|
||||
print("Results:") # a series from the printed list
|
||||
count = 1 # or they input '0' to cancel
|
||||
for result in searchResults["data"]:
|
||||
print("\n%s)\nSeries Name: " % str(count), str(result["seriesName"]))
|
||||
print("\n{})\nSeries Name: {}".format(str(count), str(result["seriesName"])))
|
||||
print()
|
||||
desc = result["overview"]
|
||||
desc = str(desc).replace("\r\n\r\n", " ") # Removing format characters
|
||||
print("Description: \n%s" % desc)
|
||||
print("Description: \n{}".format(desc))
|
||||
print()
|
||||
count = count + 1
|
||||
print()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user