Added plugins/fmylife, fixed plugins/util/misc.py
This commit is contained in:
parent
ab34472f53
commit
bdba84f861
1 changed files with 24 additions and 0 deletions
24
plugins/fmylife.py
Normal file
24
plugins/fmylife.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
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)
|
Reference in a new issue