🥅 Error codes

This commit is contained in:
NikolajDanger
2020-07-29 12:14:30 +02:00
parent ef434ecee8
commit b991ac0385
10 changed files with 489 additions and 280 deletions

View File

@ -81,19 +81,23 @@ def imageFunc():
logThis("Searching for "+search)
# Searches for the image and reads the resulting web page
page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off")
read = page.read()
tree = lxml.etree.HTML(read)
images = tree.xpath('//a[@class = "thumb"]/@href')
try:
page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off")
read = page.read()
tree = lxml.etree.HTML(read)
images = tree.xpath('//a[@class = "thumb"]/@href')
# Picks an image
number = random.randint(1,len(images))-1
image = images[number]
# Picks an image
number = random.randint(1,len(images))-1
image = images[number]
logThis("Picked image number "+str(number))
logThis("Picked image number "+str(number))
# Returns the image
logThis("Successfully returned an image")
# Returns the image
logThis("Successfully returned an image")
except:
image = "Couldn't connect to bing (error code 701)"
logThis("Couldn't connect to bing (error code 701)")
return(image)
def logThis(message : str):
@ -120,11 +124,11 @@ def findWikiPage(search : str):
else:
return page.title, content, ""
except:
logThis("Fucked up")
return "", "Sorry. Fucked that one up", ""
logThis("Fucked up (error code 1001)")
return "", "Sorry. Fucked that one up (error code 1001)", ""
else:
logThis("Couldn't find the page")
return "", "Couldn't find page", ""
logThis("Couldn't find the page (error code 1002)")
return "", "Couldn't find page (error code 1002)", ""
def makeFiles():
# Creates swcharacters.json if it doesn't exist