Added wiki command

This commit is contained in:
NikolajDanger
2020-04-03 15:57:28 +02:00
parent 69eb12f632
commit 25e7767c82
4 changed files with 54 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import urllib # Used by imageFunc
import imdb # Used by movieFunc
import time # Used for logging
import logging # Used for... you know... logging
import wikia # Used by findWikiPage
from .roll import dice
@ -118,3 +119,22 @@ def logThis(message : str):
localtime = time.asctime(time.localtime(time.time()))
print(localtime+" - "+message)
logging.info(localtime+" - "+message)
# Finds a page from the Senkulpa Wikia
def findWikiPage(search : str):
logThis("Trying to find wiki page for "+search)
wikia.set_lang("da")
searchResults = wikia.search("senkulpa",search)
if len(searchResults) > 0:
logThis("Found it")
page = wikia.page("senkulpa",searchResults[0])
content = page.content.replace(u'\xa0', u' ').split("\n")[0]
images = page.images
if len(images) > 0:
return page.title, content, images[0]+"/revision/latest?path-prefix=da"
else:
return page.title, content, ""
else:
logThis("Couldn't find the page")
return "", "Couldn't find page", ""