-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from stschoberg/book-of-the-day-plugin
bookofday plugin
- Loading branch information
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |