This commit is contained in:
deathbybandaid 2019-10-29 09:29:11 -04:00
parent dee307199b
commit 0f6c881ecd

View File

@ -178,35 +178,38 @@ class BotGif():
page = e page = e
page = None page = None
if page and not str(page.status_code).startswith(tuple(["4", "5"])): if page and not str(page.status_code).startswith(tuple(["4", "5"])):
data = json.loads(urllib.request.urlopen(url).read().decode('utf-8')) try:
results = data[self.valid_api[currentapi]['results']] data = json.loads(urllib.request.urlopen(url).read().decode('utf-8'))
resultsarray = [] results = data[self.valid_api[currentapi]['results']]
for result in results: resultsarray = []
appendresult = False for result in results:
cururl = result[self.valid_api[currentapi]['cururl']] appendresult = False
slashsplit = str(cururl).split("/") cururl = result[self.valid_api[currentapi]['cururl']]
fileextension = slashsplit[-1] slashsplit = str(cururl).split("/")
if not fileextension or fileextension == '': fileextension = slashsplit[-1]
appendresult = True if not fileextension or fileextension == '':
elif str(fileextension).endswith(".gif"): appendresult = True
appendresult = True elif str(fileextension).endswith(".gif"):
elif "." not in str(fileextension): appendresult = True
appendresult = True elif "." not in str(fileextension):
if appendresult: appendresult = True
resultsarray.append(cururl) if appendresult:
# make sure there are results resultsarray.append(cururl)
if len(resultsarray): # make sure there are results
# Create Temp dict for every result if len(resultsarray):
tempresultnum = 0 # Create Temp dict for every result
for tempresult in resultsarray: tempresultnum = 0
if tempresult not in self.badlinks: for tempresult in resultsarray:
tempresultnum += 1 if tempresult not in self.badlinks:
tempdict = { tempresultnum += 1
"returnnum": tempresultnum, tempdict = {
"returnurl": tempresult, "returnnum": tempresultnum,
"gifapi": currentapi, "returnurl": tempresult,
} "gifapi": currentapi,
self.valid_api[currentapi]["cache"][str(searchquery).lower()].append(tempdict) }
self.valid_api[currentapi]["cache"][str(searchquery).lower()].append(tempdict)
except urllib.error.HTTPError:
return
def gif_url_assemble(self, currentapi, searchquery, searchlimit, searchnsfw): def gif_url_assemble(self, currentapi, searchquery, searchlimit, searchnsfw):
# url base # url base