mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-18 10:18:48 +00:00
Did some work on checking missing images.
This commit is contained in:
parent
6b6ae46b22
commit
22a0002597
25
actions.py
25
actions.py
@ -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)
|
||||||
|
# print(response.status_code)
|
||||||
if (checkStatus(response, True) == True): # TODO there is an error occurring here when checking fanart
|
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")
|
path = os.path.join(imageType + "\\" + str(idNum) + "-" + str(num) + ".jpg")
|
||||||
obj = open(path, "wb")
|
obj = open(path, "wb")
|
||||||
obj.write(response.content)
|
obj.write(response.content)
|
||||||
obj.close()
|
obj.close()
|
||||||
print("Image found")
|
print("Image found\n")
|
||||||
else:
|
else:
|
||||||
print("Image not found")
|
print("Image not found\n")
|
||||||
print(response.status_code)
|
# 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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user