SpiceBot/spicebot_command_devexcuse/__init__.py
deathbybandaid 3ff6f08c17 test
2022-05-06 13:42:44 -04:00

24 lines
704 B
Python

import urllib
from xml.dom.minidom import parseString
from sopel import plugin
from sopel_SpiceBot_Core_Prerun import prerun
@prerun()
@plugin.command('devexcuse')
def upper(bot, trigger, comrun):
fetched_str = fetch_string()
if not fetched_str:
fetched_str = 'My humor module is broken.'
comrun.say(fetched_str)
def fetch_string():
content_url = 'http://developerexcuses.com'
content_page = urllib.request.urlopen(content_url).read()
fetched_str = parseString(content_page.replace('&', '')).getElementsByTagName('body')[0].getElementsByTagName('div')[0].getElementsByTagName('center')[0].getElementsByTagName('a')[0].childNodes[0].nodeValue
return fetched_str