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/disabled_stuff/mlia.py

35 lines
1015 B
Python
Raw Permalink Normal View History

# Plugin by Infinity - <https://github.com/infinitylabs/UguuBot>
import random
2014-02-14 04:36:57 +01:00
2013-09-04 12:30:04 +02:00
from util import hook, http
mlia_cache = []
def refresh_cache():
2013-09-04 12:30:04 +02:00
"""gets a page of random MLIAs and puts them into a dictionary """
2013-09-05 04:11:18 +02:00
url = 'http://mylifeisaverage.com/{}'.format(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):
2014-02-13 12:47:01 +01:00
"""mlia -- Gets a random quote from MyLifeIsAverage.com."""
# grab the last item in the mlia cache and remove it
2014-02-14 04:30:38 +01:00
mlia_id, text = mlia_cache.pop()
# reply with the mlia we grabbed
2014-02-14 04:30:38 +01:00
reply('({}) {}'.format(mlia_id, text))
# refresh mlia cache if its getting empty
if len(mlia_cache) < 3:
refresh_cache()