aboutsummaryrefslogtreecommitdiff
path: root/modules/isbn.py
diff options
context:
space:
mode:
authorGravatar jesopo2016-03-29 12:56:58 +0100
committerGravatar jesopo2016-03-29 12:56:58 +0100
commitf943d63098a50746f4e470e403a991a4d9713030 (patch)
treedeeb98058917d0155227211d72576f0cbab28d3f /modules/isbn.py
parentInitial commit (diff)
first commit.
Diffstat (limited to 'modules/isbn.py')
-rw-r--r--modules/isbn.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/isbn.py b/modules/isbn.py
new file mode 100644
index 00000000..67870520
--- /dev/null
+++ b/modules/isbn.py
@@ -0,0 +1,35 @@
+import json
+import Utils
+
+URL_GOOGLEBOOKS = "https://www.googleapis.com/books/v1/volumes"
+
+class Module(object):
+ _name = "ISBN"
+ def __init__(self, bot):
+ self.bot = bot
+ bot.events.on("received").on("command").on("isbn").hook(
+ self.isbn, help="Get book information from a provided ISBN",
+ min_args=1)
+
+ def isbn(self, event):
+ isbn = event["args_split"][0]
+ if len(isbn) == 10:
+ isbn = "978%s" % isbn
+ isbn = isbn.replace("-", "")
+ page = Utils.get_url(URL_GOOGLEBOOKS, get_params={
+ "q": "isbn:%s" % isbn, "country": "us"}, json=True)
+ if page:
+ if page["totalItems"] > 0:
+ book = page["items"][0]["volumeInfo"]
+ title = book["title"]
+ sub_title = book["subtitle"]
+ authors = ", ".join(book["authors"])
+ date = book["publishedDate"]
+ rating = book["averageRating"]
+ #language = book["language"]
+ event["stdout"].write("%s - %s (%s), %s (%s/5.0)" % (
+ title, authors, date, sub_title, rating))
+ else:
+ event["stderr"].write("Unable to find book")
+ else:
+ event["stderr"].write("Failed to load results")