Code Monkey home page Code Monkey logo

goodreads's Introduction

goodreads

This project is no longer maintained.

Build Status Coverage Status Documentation Status Downloads Latest Version Supported Python versions License

http://s.gr-assets.com/assets/icons/goodreads_icon_50x50-823139ec9dc84278d3863007486ae0ac.png

This package provides a Python interface for the Goodreads API. Using it, you can do pretty much anything that Goodreads allows to do with their own data.

Dependencies

This package depends on the following packages:

  • xmltodict
  • requests
  • rauth

They can be installed using pip.

sudo pip install -r requirements.txt

If you want to contribute to this package, you will need the nose package as well.

Installation

To install, run the following command from the top-level package directory.

sudo python setup.py install

Getting Started

The first thing is to request an API key from Goodreads here. Once you have it, you can create a client instance to query Goodreads.

from goodreads import client
gc = client.GoodreadsClient(<api_key>, <api_secret>)

To access some of the methods, you need OAuth for authorization.

gc.authenticate(<access_token>, <access_token_secret>)

Note that access_token and access_token_secret are different from developer key and secret. For the development step, you can call the same function with no parameters to get authorization. It will open a URL pointing a Goodreads page for OAuth permission. For your application, you can direct the user to that particular URL, ask him/her to authorize your app and save the returning access_token and access_token_secret in your database.

Getting Started: Helper

For a clean baseline reference, a Dockerfile is provided.

docker build . -f Dockerfile -t goodreads-api --target runtime

This can be used to demo OAuth usage. Given your developer key and secret, it will provide a URL to load in a browser to authorize your app, confirms that the resulting oauth values work, prints them for reference, and shows how to get them in the code.

docker run -it goodreads-api python3 -m goodreads.oauth_register --key <developer_key> --secret <developer_secret>

Examples

This package provides a Python interface for most Goodreads API methods. Here are a few examples demonstrating how to access data on Goodreads.

Books

Let's access the first book added to Goodreads! It is the book with id 1.

book = gc.book(1)

Once you have the GoodreadsBook instance for the book, you can access data for the queried book.

>>> book.title
u'Harry Potter and the Half-Blood Prince (Harry Potter, #6)'
>>> authors = book.authors
>>> authors[0].name
u'J.K. Rowling'
>>> book.average_rating
u'4.49'

Authors

You can get information about an author as well.

>>> author = gc.author(2617)
>>> author.name
u'Jonathan Safran Foer'
>>> author.works_count
u'13'
>>> author.books
[Extremely Loud and Incredibly Close, Everything Is Illuminated, Eating Animals, Tree of Codes, Everything is Illuminated & Extremely Loud and Incredibly Close, The unabridged pocketbook of lightning, The Future Dictionary of America, A Convergence of Birds: Original Fiction and Poetry Inspired by Joseph Cornell, New American Haggadah, The Sixth Borough]

Users

User data can be retrieved by user id or username.

>>> user = gc.user(1)
>>> user.name
u'Otis Chandler'
>>> user.user_name
u'otis'
>>> user.small_image_url
u'http://d.gr-assets.com/users/1189644957p2/1.jpg'

Groups

Let's find a group discussing Python and get more information about it.

>>> g = gc.find_groups("Python")
>>> g = groups[0]
>>> g['title']
u'The Computer Scientists'
>>> group = gc.group(g['id'])
>>> group.description
u'Only for Committed Self Learners and Computer Scientists Who are Starving for
Information, and Want to Advance their Skills Through: Reading, Practicing and
Discussion Computer Science and Programming Books.'

Events

Goodreads API also allows to list events happening in an area.

>>> events = gc.list_events(21229)
>>> event = events[0]
>>> event.title
u'Books and Cocktails'
>>> event.address
u'120 N. Front St.'
>>> event.city
u'Wrightsville'

Tests

First you'll need to create a file goodreads/apikey.py with (filled out) contents like:

key = "..."
secret = "..."
oauth_access_token = "..."
oauth_access_token_secret = "..."

Then run via:

docker build . -f Dockerfile -t goodreads-tests --target testing
docker run -it goodreads-tests nosetests --verbose

Documentation

Read more about this package here.

Contribution

If you find an API method that is not supported by this package, feel free to create a Github issue. Also, you are more than welcome to submit a pull request for a bug fix or additional feature.

License

MIT License

Acknowledgment

Thanks to Paul Shannon for providing 'goodreads' package at PyPI.

goodreads's People

Contributors

bcipriano avatar dreadpirateshawn avatar mcrapet avatar sefakilic avatar tatianass avatar varzan avatar

Watchers

 avatar  avatar

goodreads's Issues

book.popular_shelves and book.series_works can be empty

Example of both cases:

OrderedDict([
  ('id', OrderedDict([
    ('@type', 'integer'),
    ('#text', '546454')])),
    ('isbn', '0532601467'),
    ('isbn13', '9780532601463'),
    ('text_reviews_count', OrderedDict([('@type', 'integer'), ('#text', '98')])),
    ('uri', 'kca://book/amzn1.gr.book.v1.nc7d34Wasx0hXPwjH9DMLQ'),
    ('title', 'The Voyage of the Space Beagle'),
    ('title_without_series', 'The Voyage of the Space Beagle'),
    ('image_url', 'https://s.gr-assets.com/assets/nophoto/book/111x148-bcc042a9c91a29c1d680899eff700a03.png'),
    ('small_image_url', 'https://s.gr-assets.com/assets/nophoto/book/50x75-a91bf249278a81aabab721ef782c4a74.png'),
    ('large_image_url', None),
    ('link', 'https://www.goodreads.com/book/show/546454.The_Voyage_of_the_Space_Beagle'),
    ('num_pages', '192'),
    ('format', 'Paperback'),
    ('edition_information', None),
    ('publisher', 'Macfadden-Bartell'),
    ('publication_day', None),
    ('publication_year', '1963'),
    ('publication_month', None),
    ('average_rating', '3.86'),
    ('ratings_count', '3137'),
    ('description', None),
    ('authors', OrderedDict([
      ('author', OrderedDict([
        ('id', '1293688'),
        ('name', 'A.E. van Vogt'),
        ('role', None),
        ('image_url', OrderedDict([
          ('@nophoto', 'false'),
          ('#text', 'https://images.gr-assets.com/authors/1226200601p5/1293688.jpg')
        ])),
        ('small_image_url', OrderedDict([
          ('@nophoto', 'false'),
          ('#text', 'https://images.gr-assets.com/authors/1226200601p2/1293688.jpg')
        ])),
        ('link', 'https://www.goodreads.com/author/show/1293688.A_E_van_Vogt'),
        ('average_rating', '3.84'),
        ('ratings_count', '38578'),
        ('text_reviews_count', '2280')
      ]))
    ])),
    ('published', '1963'),
    ('work', OrderedDict([('id', '2016616'), ('uri', 'kca://work/amzn1.gr.work.v1.3tDylDehuKu4BaHTdlO5Ow')]))
  ])

Feature request: expose "date_added" for reviews

Sample api data:

<reviews start="41" end="60" total="587">
  <review>
    ...
    <date_added>Thu Apr 04 19:28:50 -0700 2019</date_added>
    ...
  </review>

Desired method: date_added

Return value: datetime object

Use-case: Determining which books have been on my to-read shelf the longest.

tests: unclear run steps, difficult to debug, many missing asserts

Unclear run steps:
Add makefile or similar for tests, perhaps they use pytest?

Difficult to debug:
Actual value isn't reported by asserts, simply that it doesn't match expected value, e.g.

FAIL: tests.author_test.TestAuthor.test_gender
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/goodreads/tests/author_test.py", line 36, in test_gender
    assert self.author.gender == 'malt'
AssertionError

Many missing asserts:
Various tests can never fail because they don't actually assert anything, e.g.

    def test_born_at(self):
        self.author.born_at == '1938/01/10'

book.gid sometimes returns ordereddict rather than id

From some vectors, the book data presents the gid as text, whereas other vectors returns the book data as an OrderedDict.

>>> from goodreads import client
>>> gc = client.GoodreadsClient("...", "...")
>>> books = gc.shelf("18761398", 'to-read')
>>> books[0].gid
OrderedDict([('@type', 'integer'), ('#text', '25109947')])
>>> book = gc.book(25109947)
>>> book.gid
'25109947'

Reviews are returned as single dict rather than list if only one is present in a shelf

When a shelf contains only a single item (or for instance the last page of a shelf does), then it's returned as a single dict rather than a list of dicts.

Example URL (although this will undoubtedly stop repro'ing as content changes):
https://www.goodreads.com/review/list/18761398.xml?v=2&page=3&shelf=3-star

This is ultimately an xml issue, since the spec does not disambiguate "always single child" vs "list that happens to be a single item". See martinblech/xmltodict#14 for discussion, and see https://stackoverflow.com/a/39068400/128977 for a workaround in newer xmltodict versions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.