Did some work on checking missing images.

This commit is contained in:
Clayton Wilson 2017-11-08 08:16:22 -05:00
parent 6b6ae46b22
commit 22a0002597
2 changed files with 27 additions and 22 deletions

View File

@ -125,13 +125,14 @@ def searchRemainder(imageType, saveNameList, idNum):#Finds any images missing fr
missingList = findMissing(numbers) missingList = findMissing(numbers)
minNum = min(numbers) minNum = min(numbers)
maxNum = max(numbers) maxNum = max(numbers)
tryMissing(missingList, minNum, maxNum, idNum, imageType) tryMissing(missingList, minNum, maxNum, idNum, imageType)
def findMissing(numbers): # TODO test this def findMissing(numbers): # TODO test this
start, end = numbers[0], numbers[-1] start, end = numbers[0], numbers[-1]
return sorted(set(range(start, end + 1)).difference(numbers)) 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"): if (imageType is "fanart"):
startDirectory = "fanart/original/" startDirectory = "fanart/original/"
elif (imageType is "poster"): elif (imageType is "poster"):
@ -140,25 +141,29 @@ def tryMissing(missingNums, min, max, idNum, imageType):
for num in missingNums: for num in missingNums:
fileName = startDirectory + str(idNum) + "-" + str(num) + ".jpg" fileName = startDirectory + str(idNum) + "-" + str(num) + ".jpg"
# fileName = "%s%s-%d.jpg" % startDirectory, idNum, missingNums[num] # fileName = "%s%s-%d.jpg" % startDirectory, idNum, missingNums[num]
try: # try:
print("\nTrying... " + fileName) print("\nTrying... " + fileName)
dlUrl = "https://www.thetvdb.com/banners/" + fileName dlUrl = "https://www.thetvdb.com/banners/" + fileName
print("url is: " + dlUrl) # print("url is: " + dlUrl)
response = requests.get(dlUrl) response = requests.get(dlUrl)
if (checkStatus(response, True) == True): # TODO there is an error occurring here when checking fanart # print(response.status_code)
path = os.path.join(imageType + "\\" + str(idNum) + "-" + str(num) + ".jpg") if (checkStatus(response, True) == True): # TODO there is an error occurring here when checking fanart
obj = open(path, "wb") path = os.path.join(imageType + "\\" + str(idNum) + "-" + str(num) + ".jpg")
obj.write(response.content) obj = open(path, "wb")
obj.close() obj.write(response.content)
print("Image found") obj.close()
else: print("Image found\n")
print("Image not found") else:
print(response.status_code) 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): def download(imageType, parsed_respObj):
counter = 0 counter = 0

View File

@ -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.") print("An error occurred. Please check your internet and try again.")
quit() quit()
if (checkStatus(response, True)): if (checkStatus(response, False)):
parsed_token = json.loads(response.content) parsed_token = json.loads(response.content)
token = parsed_token["token"] token = parsed_token["token"]
return token return token
@ -26,8 +26,8 @@ def checkStatus(response, v):
if (v == True): if (v == True):
print("\nAn error occurred.") print("\nAn error occurred.")
print("HTTP Code: " + str(response.status_code)) print("HTTP Code: " + str(response.status_code))
error = json.loads(response.content) # error = json.loads(response.content) # TODO move this somewhere else
print("Response : " + error["Error"]) # print("Response : " + error["Error"])
return False return False
else: else:
return True return True