Skip to content

Commit

Permalink
Merge pull request #66 from Tuanthai4444/master
Browse files Browse the repository at this point in the history
PR for story.py
  • Loading branch information
Abdur-rahmaanJ authored Nov 25, 2019
2 parents 913ccac + 327a888 commit f3b3346
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions honeybot/plugins/story.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
"""
[story.py]
Story Plugin
[Author]
Tuan Thai
[About]
Sends a random story
Sourced stories from
http://www.read.gov/aesop/001.html
[Commands]
>>> .story
returns random story
"""

import random
import requests
from bs4 import BeautifulSoup


class Plugin:
def __init__(self):
pass

def story(self):
number = random.randint(2, 147)
if number < 10:
story = "00" + str(number)
elif number < 100:
story = "0" + str(number)
else:
story = str(number)

story_url = requests.get("http://www.read.gov/aesop/" + story + ".html")
soup = BeautifulSoup(story_url.content, "html.parser")
texts = soup.find('div', {"id": "page"})
for paragraph in texts.findAll('p'):
return str(paragraph.text)

def run(self, incoming, methods, info, bot_info):
try:
if info['command'] == 'PRIVMSG' and info['args'][1] == '.story':
methods['send'](info['address'], Plugin.story(self))
except Exception as e:
print('woops plugin error: ', e)

0 comments on commit f3b3346

Please sign in to comment.