2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

10/14/2017: Goodreads - Using Python To List To Read Shelf

I’ve been using http://goodreads.com for several years and have good substantial list of books on my To Read shelf. I thought it would be interesting to see how hard using the GoodReads API would be.

Not too difficult.

First I registered with GoodReads to get an API key. Then I ran the following curl command.

export GDKEY=XXX
curl --silent \
  -o goodreads-to-read.xml \
  "https://www.goodreads.com/review/list/32902953.xml?key=$GDKEY&v=2&shelf=to-read&per_page=200"

I created a small python script to handle reading the XML.

import xml.etree.ElementTree as etree
tree = etree.parse('/usr/src/app/goodreads-to-read.xml')
root = tree.getroot()
for child in root:
    if child.tag == 'reviews':
        for review in child:
            for reviewElements in review:
                if reviewElements.tag == 'book':
                    for bookElements in reviewElements:
                        if bookElements.tag == 'title':
                            print(bookElements.text)

The last step runs the script:

docker run \
  --rm=true \
  -v $(pwd):/usr/src/app \
  python:3.6.3 \
  python /usr/src/app/parsexml.py | head | sort

You could use python directly, of course, if you have it already installed.



subscribe via RSS