Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bookofday plugin #23

Merged
merged 2 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum nice but you have to go to https://bookoftheday.org . If you want to contribute a dad joke plugin, just modify the name and command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah my mistake. I was using that url while debugging. I just commited with the updated bookoftheday.org

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)