SpiceBot/spicebot_command_devexcuse/__init__.py
deathbybandaid 570b7c7148 test
2023-01-24 10:57:37 -05:00

26 lines
605 B
Python

import requests
from lxml import html
from sopel import plugin
from sopel_SpiceBot_Core_Prerun import sbprerun
@sbprerun()
@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'
response = requests.get(content_url)
tree = html.fromstring(response.content)
title_elem = tree.xpath('/html/body/div[1]/center/a')[0].text
fetched_str = str(title_elem)
return fetched_str