From 22a00025972a6665bb9cbc6e0623edfc3ff63592 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Wed, 8 Nov 2017 08:16:22 -0500 Subject: [PATCH] Did some work on checking missing images. --- actions.py | 43 ++++++++++++++++++++++++------------------- checks.py | 6 +++--- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/actions.py b/actions.py index 6caa19a..26291e0 100644 --- a/actions.py +++ b/actions.py @@ -125,13 +125,14 @@ def searchRemainder(imageType, saveNameList, idNum):#Finds any images missing fr missingList = findMissing(numbers) minNum = min(numbers) maxNum = max(numbers) + tryMissing(missingList, minNum, maxNum, idNum, imageType) def findMissing(numbers): # TODO test this start, end = numbers[0], numbers[-1] return sorted(set(range(start, end + 1)).difference(numbers)) -def tryMissing(missingNums, min, max, idNum, imageType): +def tryMissing(missingNums, minNum, maxNum, idNum, imageType): if (imageType is "fanart"): startDirectory = "fanart/original/" elif (imageType is "poster"): @@ -140,25 +141,29 @@ def tryMissing(missingNums, min, max, idNum, imageType): for num in missingNums: fileName = startDirectory + str(idNum) + "-" + str(num) + ".jpg" # fileName = "%s%s-%d.jpg" % startDirectory, idNum, missingNums[num] - try: - print("\nTrying... " + fileName) - dlUrl = "https://www.thetvdb.com/banners/" + fileName - print("url is: " + dlUrl) - response = requests.get(dlUrl) - 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") - obj = open(path, "wb") - obj.write(response.content) - obj.close() - print("Image found") - else: - print("Image not found") - print(response.status_code) + # try: + print("\nTrying... " + fileName) + dlUrl = "https://www.thetvdb.com/banners/" + 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") + obj = open(path, "wb") + obj.write(response.content) + obj.close() + print("Image found\n") + else: + print("Image not found\n") + # print(response.status_code) + + # except Exception as e: + # print("response code: " + str(response.status_code)) + # print("Check: " + dlUrl) + # print(e) + + while minNum > 1: # Checking lower bounds - except Exception as e: - print("repsonse code: " + str(response.status_code)) - print("Check: " + dlUrl) - print(fileName + " doesn't exist") def download(imageType, parsed_respObj): counter = 0 diff --git a/checks.py b/checks.py index 9c8e6db..7a3a10b 100644 --- a/checks.py +++ b/checks.py @@ -14,7 +14,7 @@ def getToken(data):#TODO add a timeout and try catch to all requests print("An error occurred. Please check your internet and try again.") quit() - if (checkStatus(response, True)): + if (checkStatus(response, False)): parsed_token = json.loads(response.content) token = parsed_token["token"] return token @@ -26,8 +26,8 @@ def checkStatus(response, v): if (v == True): print("\nAn error occurred.") print("HTTP Code: " + str(response.status_code)) - error = json.loads(response.content) - print("Response : " + error["Error"]) + # error = json.loads(response.content) # TODO move this somewhere else + # print("Response : " + error["Error"]) return False else: return True