Skip to content

Instantly share code, notes, and snippets.

@slackorama
Created July 11, 2011 21:47
Show Gist options
  • Save slackorama/1076874 to your computer and use it in GitHub Desktop.
Save slackorama/1076874 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from xml.dom import minidom
import datetime, time
from email.utils import parsedate
import sys, codecs
# wget -O goodreads.xml
# "http://www.goodreads.com/review/list/1519786.xml?key=LV0wx2GkLwTCVLSFIiNQBQ&v=2&shelf=read&per_page=200"
import cgi
timeformat = "%a %b %d %H:%M:%S %X %Y"
xmldoc = minidom.parse("goodreads.xml")
reviews = xmldoc.firstChild.childNodes[3]
for review in reviews.getElementsByTagName('review'):
read_at = review.getElementsByTagName('read_at')[0].firstChild.data
d = datetime.datetime.fromtimestamp(time.mktime(parsedate(read_at)))
if d.year == 2010:
title = review.getElementsByTagName('title')[0].childNodes[1].data.encode('UTF-8')
isbn_13 = review.getElementsByTagName('isbn13')[0].firstChild
authors = review.getElementsByTagName('authors')
if len(authors) == 1:
author = authors[0].getElementsByTagName('name')[0].firstChild.data.encode('UTF-8')
else:
author = 'Multiple Authors'
if isbn_13:
print '<li><a href="http://www.amazon.com/gp/search?keywords=%s&index=books&linkCode=qs&tag=slackorama-20">%s</a> by %s </li>' % (isbn_13.data,title, author)
else:
print title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment