This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/fmylife.py

25 lines
692 B
Python
Raw Normal View History

import re
from util import hook, http, misc
from urllib2 import HTTPError
from BeautifulSoup import BeautifulSoup
url = 'http://www.fmylife.com/random'
@hook.command(autohelp=False)
def fml(inp):
".fml -- gets a random quote from fmyfife.com"
try:
page = http.get(url)
except (HTTPError, IOError):
return "I tried to use .fml, but it was broken. FML"
soup = BeautifulSoup(page)
soup.find('div', id='submit').extract()
post = soup.body.find('div', 'post')
id = int(post.find('a', 'fmllink')['href'].split('/')[-1])
body = misc.strip_html(' '.join(link.renderContents() for link in post('a', 'fmllink')))
return '(#%d) %s' % (id, body)