Made some improvements to search functionality

This commit is contained in:
Clayton Wilson 2017-11-07 15:52:43 -05:00
parent cc3c89c5d6
commit 6b6ae46b22
2 changed files with 16 additions and 10 deletions

View File

@ -75,11 +75,12 @@ def clearFolders(): # TODO implement this
if os.path.exists(folder): if os.path.exists(folder):
imageList = os.listdir(folder) imageList = os.listdir(folder)
if len(imageList) != 0: if len(imageList) != 0:
print("Clearing " + folder)
for x in imageList: # TODO check if folder is empty for x in imageList: # TODO check if folder is empty
print("Deleting " + x) print("Deleting " + x)
delPath = os.path.join(folder + "\\" + x) delPath = os.path.join(folder + "\\" + x)
os.remove(delPath) os.remove(delPath)
print(folder + " cleared\n") print()
else: else:
print("'" + folder + "'" + " is already empty") print("'" + folder + "'" + " is already empty")
else: else:
@ -116,10 +117,10 @@ def searchRemainder(imageType, saveNameList, idNum):#Finds any images missing fr
if (name.rfind("-") != -1): if (name.rfind("-") != -1):
hyphenIndex = name.rfind("-") hyphenIndex = name.rfind("-")
hyphenSuffix = name[hyphenIndex + 1:] hyphenSuffix = name[hyphenIndex + 1:]
value = hyphenSuffix.replace(".jpg", "") filenum = hyphenSuffix.replace(".jpg", "")
numbers.append(int(value)) numbers.append(int(filenum))
else: 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 numbers.sort
missingList = findMissing(numbers) missingList = findMissing(numbers)
minNum = min(numbers) minNum = min(numbers)
@ -139,16 +140,20 @@ 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]
print("This is missing: " + fileName)
try: try:
print("Trying... " + fileName) print("\nTrying... " + fileName)
dlUrl = "https://www.thetvdb.com/banners/" + fileName dlUrl = "https://www.thetvdb.com/banners/" + fileName
print("url is: " + dlUrl)
response = requests.get(dlUrl) response = requests.get(dlUrl)
if (checkStatus(response, False) == True): 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")
else:
print("Image not found")
print(response.status_code)
except Exception as e: except Exception as e:
print("repsonse code: " + str(response.status_code)) print("repsonse code: " + str(response.status_code))

View File

@ -7,6 +7,7 @@ import urllib.parse
import dateutil import dateutil
from actions import clearFolders from actions import clearFolders
from actions import clear_screen
from actions import downloadImages from actions import downloadImages
from actions import searchImages from actions import searchImages
from checks import checkTimestamp from checks import checkTimestamp
@ -64,8 +65,8 @@ def search():
title = -1 title = -1
print() print()
clear_screen()
while title < 0 or title > len(searchResults["data"]) - 1: # Looping until the user chooses while title < 0 or title > len(searchResults["data"]) - 1: # Looping until the user chooses
print("==================================")
print("Results:") # a series from the printed list print("Results:") # a series from the printed list
count = 1 # or they input '0' to cancel count = 1 # or they input '0' to cancel
for result in searchResults["data"]: 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("fanart", fanart, idNum) # TODO find a better way to pass these variables. Constructor?
downloadImages("poster", poster, idNum) downloadImages("poster", poster, idNum)
downloadImages("banner", banner, idNum) downloadImages("banner", banner, idNum)
print("All downloads finished!") print("\nAll downloads finished!\n")
return None return None