SpiceBot/spicebot_command_devexcuse/__init__.py
deathbybandaid aae8db0bbd test
2022-05-06 14:01:24 -04:00

28 lines
680 B
Python

import requests
from lxml import html
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'
response = requests.get(content_url)
tree = html.fromstring(response.content)
title_elem = tree.xpath('/html/body/div[1]/center/a')
fetched_str = str(title_elem)
return fetched_str
# .wrapper > center:nth-child(1) > a:nth-child(1)
# /html/body/div[1]/center/a