Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
"""Grab the books from the current year from goodreads and emit some HTML.
import requests
from xml.dom import minidom
import datetime, time
from email.utils import parsedate
import sys
goodreads_key = sys.argv[1]
# URL =
url = "{}&v=2&format=xml&id=1519786&per_page=200&shelf=read".format(goodreads_key)
timeformat = "%a %b %d %H:%M:%S %X %Y"
req = requests.get(url)
if req.status_code != 200:
print('Bad request!')
xmldoc = minidom.parseString(req.content)
year = - 1
reviews = xmldoc.firstChild.childNodes[3]
for review in reviews.getElementsByTagName('review'):
if review.getElementsByTagName('read_at')[0].firstChild is None:
read_at = review.getElementsByTagName('read_at')[0]
d = datetime.datetime.fromtimestamp(time.mktime(parsedate(read_at)))
if d.year == year:
title = review.getElementsByTagName('title')[0].childNodes[0].data.encode('UTF-8')
isbn_13 = review.getElementsByTagName('isbn13')[0].firstChild
authors = review.getElementsByTagName('authors')
rating = review.getElementsByTagName('rating')[0]'UTF-8')
if len(authors) == 1:
author = authors[0].getElementsByTagName('name')[0]'UTF-8')
author = 'Multiple Authors'
if isbn_13:
print '<li><a href=";index=books&amp;linkCode=qs&amp;tag=slackorama-20">%s</a> by %s (%s stars)</li>' % ('UTF-8'),title, author, rating)
print '<li>%s</li>' % title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment