Testing the ability to include libraries with the bot
This commit is contained in:
parent
c44b1dcd6a
commit
6b4042972b
18 changed files with 6477 additions and 12 deletions
|
@ -1,24 +1,20 @@
|
|||
# Plugin by Lukeroge
|
||||
|
||||
from util import hook, http
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
from collections import defaultdict
|
||||
|
||||
fml_cache = defaultdict()
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
fml_cache = []
|
||||
|
||||
|
||||
def refresh_cache():
|
||||
""" gets a page of random FMLs and puts them into a dictionary """
|
||||
page = http.get('http://www.fmylife.com/random/')
|
||||
soup = BeautifulSoup(page)
|
||||
soup = BeautifulSoup(page, 'lxml')
|
||||
|
||||
for e in soup.findAll('div', {'class': 'post article'}):
|
||||
for e in soup.find_all('div', {'class': 'post article'}):
|
||||
id = int(e['id'])
|
||||
# get the text of the FML
|
||||
text = ''.join(e.find('p').findAll(text=True))
|
||||
text = ''.join(e.find('p').find_all(text=True))
|
||||
text = http.unescape(text)
|
||||
# append to the dictionary
|
||||
fml_cache[id] = text
|
||||
fml_cache.append((id, text))
|
||||
|
||||
# do an initial refresh of the cache
|
||||
refresh_cache()
|
||||
|
@ -29,7 +25,7 @@ def fml(inp, reply=None):
|
|||
"fml -- Gets a random quote from fmyfife.com."
|
||||
|
||||
# grab the last item in the fml cache and remove it
|
||||
id, text = fml_cache.popitem()
|
||||
id, text = fml_cache.pop()
|
||||
# reply with the fml we grabbed
|
||||
reply('(#%d) %s' % (id, text))
|
||||
# refresh fml cache if its getting empty
|
||||
|
|
Reference in a new issue