Skip to content

Commit

Permalink
Merge pull request #23 from stschoberg/book-of-the-day-plugin
Browse files Browse the repository at this point in the history
bookofday plugin
  • Loading branch information
Abdur-rahmaanJ committed Jul 3, 2019
2 parents 1b42add + ed3352d commit 7927d4c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions honeybot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def load_plugins(self, plugins_to_load):
try:
module = importlib.import_module('plugins.' + file)
except ModuleNotFoundError as e:
logger.warning(f"module import error, skipped' {e} in {file}")
logger.warning("module import error, skipped' {e} in {file}")
obj = module.Plugin
list_to_add.append(obj)

Expand Down Expand Up @@ -251,7 +251,7 @@ def pull(self):

if len(data) == 0:
try:
logger.critical(f'<must handle reconnection - {len(data)}==0>')
logger.critical('<must handle reconnection - {len(data)}==0>')
sys.exit()
except Exception as e:
logger.info(e)
Expand All @@ -262,13 +262,13 @@ def pull(self):
def registered_run(self):
self.connect()
self.identify()
self.greet()
#self.greet()
self.load_plugins('PLUGINS')
self.pull()

def unregistered_run(self):
self.connect()
self.greet()
#self.greet()
self.load_plugins('PLUGINS')
self.pull()

Expand Down
34 changes: 34 additions & 0 deletions honeybot/plugins/book_of_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
[book_of_day.py]
Book of the Day Plugin
[Author]
Schoberg, UMD
[About]
using bookoftheday.org, get the title and link of the book of the day
[Commands]
>>> .bookoftheday
https://bookoftheday.org/fleishman-is-in-trouble-taffy-brodesser-akner/
"""

import requests
from bs4 import BeautifulSoup

class Plugin:
def __init__(self):
pass

def book(self):
headers = {'Accept' : 'application/json'}
r = requests.get('http://bookoftheday.org', headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
d = soup.find_all("div", {"class":"chpcs_foo_content"})

return str(d[0].a['href'])

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

0 comments on commit 7927d4c

Please sign in to comment.