mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-15 17:28:46 +00:00
Made some improvements to search functionality
This commit is contained in:
parent
cc3c89c5d6
commit
6b6ae46b22
21
actions.py
21
actions.py
@ -75,11 +75,12 @@ def clearFolders(): # TODO implement this
|
||||
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)
|
||||
delPath = os.path.join(folder + "\\" + x)
|
||||
os.remove(delPath)
|
||||
print(folder + " cleared\n")
|
||||
print()
|
||||
else:
|
||||
print("'" + folder + "'" + " is already empty")
|
||||
else:
|
||||
@ -116,10 +117,10 @@ def searchRemainder(imageType, saveNameList, idNum):#Finds any images missing fr
|
||||
if (name.rfind("-") != -1):
|
||||
hyphenIndex = name.rfind("-")
|
||||
hyphenSuffix = name[hyphenIndex + 1:]
|
||||
value = hyphenSuffix.replace(".jpg", "")
|
||||
numbers.append(int(value))
|
||||
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: %s" % name) # Error checking
|
||||
numbers.sort
|
||||
missingList = findMissing(numbers)
|
||||
minNum = min(numbers)
|
||||
@ -139,16 +140,20 @@ 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]
|
||||
print("This is missing: " + fileName)
|
||||
try:
|
||||
print("Trying... " + fileName)
|
||||
print("\nTrying... " + fileName)
|
||||
dlUrl = "https://www.thetvdb.com/banners/" + fileName
|
||||
print("url is: " + dlUrl)
|
||||
response = requests.get(dlUrl)
|
||||
if (checkStatus(response, False) == True):
|
||||
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
|
||||
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)
|
||||
|
||||
except Exception as e:
|
||||
print("repsonse code: " + str(response.status_code))
|
||||
|
||||
@ -7,6 +7,7 @@ import urllib.parse
|
||||
import dateutil
|
||||
|
||||
from actions import clearFolders
|
||||
from actions import clear_screen
|
||||
from actions import downloadImages
|
||||
from actions import searchImages
|
||||
from checks import checkTimestamp
|
||||
@ -64,8 +65,8 @@ def search():
|
||||
|
||||
title = -1
|
||||
print()
|
||||
clear_screen()
|
||||
while title < 0 or title > len(searchResults["data"]) - 1: # Looping until the user chooses
|
||||
print("==================================")
|
||||
print("Results:") # a series from the printed list
|
||||
count = 1 # or they input '0' to cancel
|
||||
for result in searchResults["data"]:
|
||||
@ -96,5 +97,5 @@ def search():
|
||||
downloadImages("fanart", fanart, idNum) # TODO find a better way to pass these variables. Constructor?
|
||||
downloadImages("poster", poster, idNum)
|
||||
downloadImages("banner", banner, idNum)
|
||||
print("All downloads finished!")
|
||||
print("\nAll downloads finished!\n")
|
||||
return None
|
||||
|
||||
Loading…
Reference in New Issue
Block a user