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
2011-11-20 22:23:31 +13:00

24 lines
718 B
Python

import re
from util import hook, http, misc
from urlparse import urljoin
from BeautifulSoup import BeautifulSoup
base_url = 'http://www.fmylife.com/'
rand_url = urljoin(base_url, 'random')
spec_url = urljoin(base_url, '%d')
error = 'Today I couldn\'t seem to access fmylife.com.. FML'
@hook.command(autohelp=False)
@hook.command("fml")
def fmylife(inp):
page = http.get(rand_url)
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 = strip_html(decode(' '.join(link.renderContents() for link in post('a', 'fmllink')), 'utf-8'))
return u'%s: (%d) %s' % (nick, id, body)