Added the MLIA plugin by @infinitylabs from infinitylabs/UguuBot
This commit is contained in:
parent
c6ecd1db81
commit
c0e8c4efdc
2 changed files with 35 additions and 0 deletions
|
@ -12,6 +12,9 @@ frdmn
|
|||
puffrfish
|
||||
nasonfish
|
||||
|
||||
We are using code from the following projects:
|
||||
./plugins/mlia.py - https://github.com/infinitylabs/UguuBot
|
||||
|
||||
Special Thanks:
|
||||
Rmmh (created skybot!)
|
||||
lahwran (for his advice and stuff I stole from his skybot fork!)
|
||||
|
|
32
plugins/mlia.py
Normal file
32
plugins/mlia.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Plugin by Infinity - <https://github.com/infinitylabs/UguuBot>
|
||||
|
||||
from util import hook, http
|
||||
import random
|
||||
|
||||
mlia_cache = []
|
||||
|
||||
|
||||
def refresh_cache():
|
||||
"gets a page of random MLIAs and puts them into a dictionary "
|
||||
url = 'http://mylifeisaverage.com/%s' % random.randint(1, 11000)
|
||||
soup = http.get_soup(url)
|
||||
|
||||
for story in soup.find_all('div', {'class': 'story '}):
|
||||
mlia_id = story.find('span', {'class': 'left'}).a.text
|
||||
mlia_text = story.find('div', {'class': 'sc'}).text.strip()
|
||||
mlia_cache.append((mlia_id, mlia_text))
|
||||
|
||||
# do an initial refresh of the cache
|
||||
refresh_cache()
|
||||
|
||||
|
||||
@hook.command(autohelp=False)
|
||||
def mlia(inp, reply=None):
|
||||
"mlia -- Gets a random quote from MyLifeIsAverage.com."
|
||||
# grab the last item in the mlia cache and remove it
|
||||
id, text = mlia_cache.pop()
|
||||
# reply with the mlia we grabbed
|
||||
reply('(%s) %s' % (id, text))
|
||||
# refresh mlia cache if its getting empty
|
||||
if len(mlia_cache) < 3:
|
||||
refresh_cache()
|
Reference in a new issue