Skip to content

Instantly share code, notes, and snippets.

@benmj
Created January 17, 2013 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmj/4552480 to your computer and use it in GitHub Desktop.
Save benmj/4552480 to your computer and use it in GitHub Desktop.
fooling around with goodreads api
# http://www.goodreads.com/book/title.xml?author=Roberto+Bola%C3%B1o&key=Iz76TB8T47u8g4T90VKg&title=Savage+Detectives&format=json
body = urllib.urlencode({ 'author' : 'Karen Russel', 'title' : 'Swamplandia', 'format' : 'json' })
response, content = client.request('%s/book/title.xml' % url,
'GET', body, headers)
body = urllib.urlencode({'name': 'read', 'book_id': 8584686})
headers = {'content-type': 'application/x-www-form-urlencoded'}
response, content = client.request('%s/shelf/add_to_shelf.xml' % url,
'POST', body, headers)
# Add review
# Add book reviews for members using OAuth. You'll need to register your app (required).
# URL: http://www.goodreads.com/review.xml
# HTTP method: POST
# Parameters:
# book_id: Goodreads book_id (required)
# review[review]: Text of the review (optional)
# review[rating]: Rating (0-5) (optional, default is 0 (No rating))
# review[read_at]: Date (YYYY-MM-DD format, e.g. 2008-02-01) (optional)
# shelf: read|currently-reading|to-read|<USER SHELF NAME> (optional, must exist, see: shelves.list)
# swamplandia
body = urllib.urlencode({'book_id' : 8584686, 'review[rating]' : 3, 'review[read_at]' : '2012-12-15', 'shelf' : 'read' })
body = urllib.urlencode({'book_id' : 8584686, 'shelf' : 'read' })
response, content = client.request('%s/review.xml' % url, 'POST', body, headers)
body = urllib.urlencode({ 'author' : 'Karen Russel', 'title' : 'Swamplandia', 'format' : 'json' })
response, content = client.request('%s/book/title.xml' % url,
'GET', body, headers)
body = urllib.urlencode({ 'author' : 'Robert Johnson', 'title' : 'She' })
response, content = client.request('%s/book/title.xml' % url, 'GET', body, headers)
if response['status'] != '200':
raise Exception('Error locating book: %s' % response['status'])
else:
root = ET.fromstring(content)
book = root.findall('book')[0]
print "Found what you were looking for '%s' (ID: %s)" % (book.findall('title')[0].text, book.findall('id')[0].text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment