28 lines
683 B
Python
28 lines
683 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')[0]
|
|
fetched_str = str(title_elem)
|
|
return fetched_str
|
|
# .wrapper > center:nth-child(1) > a:nth-child(1)
|
|
# /html/body/div[1]/center/a
|