GithubHelp home page GithubHelp logo

goodreads's Introduction

goodreads

This project is no longer maintained.

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

image

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.

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'

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 mcrapet avatar sefakilic avatar varzan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goodreads's Issues

Is this wrapper Python 2 only?

getting following error in Python3:

>>> from goodreads import client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/avi/.tmp/goodreads/venv/lib/python3.4/site-packages/goodreads/client.py", line 2, in <module>
    from session import GoodreadsSession
ImportError: No module named 'session'

Too slow

Hi I'm trying to do a telegram bot using the goodreads API, the problem is the results are getting too late, so the responde id for the telegram message ID expired.

Is there something I can do to get the search results faster?

    if query:
        books = gc.search_books(q=query)
        for book in books:
            print(book.title)
            results.append(InlineQueryResultArticle(
                id=uuid4(),
                title=book.title,
                url=book.link,
                description=book.description,
                thumb_url=book.small_image_url,
                input_message_content=InputTextMessageContent(
                    query.upper())))

    update.inline_query.answer(results)

TypeError: __init__() missing 1 required positional argument: 'client'

Hey I'm not sure if this a bug or if I am doing it incorrectly. I am trying to access my owned books by doing this:

from goodreads import client

api_key = "my api key"
api_secret = "my secret"
gc = client.GoodreadsClient(api_key, api_secret)
gc.authenticate()

user_id = my good reads id
user = gc.user(user_id)
owned_books = user.owned_books()
for owned_book in owned_books:
    print(owned_book.book)

User details from review

Hi,
I am using the recent_reviews function and the review object does not have any property to retrieve user details. It would be nice to get user details from the review.

Thanks
Aravindan

pip install

pip install gives the following error message:

Downloading/unpacking goodreads from https://pypi.python.org/packages/source/G/Goodreads/goodreads-0.2.1.tar.gz#md5=f7c04e3e368479e53a275ca840a5eef2
  Downloading goodreads-0.2.1.tar.gz
  Running setup.py (path:/tmp/pip_build_root/goodreads/setup.py) egg_info for package goodreads
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_root/goodreads/setup.py", line 7, in <module>
        long_description = pypandoc.convert('README.md', 'rst'),
      File "/usr/local/lib/python2.7/dist-packages/pypandoc.py", line 94, in convert
        outputfile=outputfile, filters=filters)
      File "/usr/local/lib/python2.7/dist-packages/pypandoc.py", line 112, in _convert
        raise RuntimeError('Missing format!')
    RuntimeError: Missing format!
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_root/goodreads/setup.py", line 7, in <module>

    long_description = pypandoc.convert('README.md', 'rst'),

  File "/usr/local/lib/python2.7/dist-packages/pypandoc.py", line 94, in convert

    outputfile=outputfile, filters=filters)

  File "/usr/local/lib/python2.7/dist-packages/pypandoc.py", line 112, in _convert

    raise RuntimeError('Missing format!')

RuntimeError: Missing format!

----------------------------------------

Https rather than http using OAuth protocol

The oauth_init() function needs to be updated with the address having "https" rather than "http", in the following way:

def oauth_init(self):
        """Start outh and return authorization url."""
        service = OAuth1Service(
            consumer_key=self.client_key,
            consumer_secret=self.client_secret,
            name='goodreads',
            request_token_url='https://www.goodreads.com/oauth/request_token',
            authorize_url='https://www.goodreads.com/oauth/authorize',
            access_token_url='https://www.goodreads.com/oauth/access_token',
            base_url='https://www.goodreads.com/'
        )

Error with Python 3.5

I get the below error when I try to use goodreads wrapper -

Traceback (most recent call last):
File "./getQuotes.py", line 3, in
from goodreads import client
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/goodreads/client.py", line 2, in
from session import GoodreadsSession

Does this wrapper work with python3.5?

Thanks.

Changed raw_input() into input() for Python

In:
goodreads/goodreads/client.py line 46
I believe that that
"while raw_input("Have you authorized me? (y/n)") != 'y':"
Should be
"while input("Have you authorized me? (y/n)") != 'y':"
Right now it doesn't work in Python 3.

Travis CI build fail

The keys needed to decrypt the github.properties.enc file are set as two environment variables ($encrypted_7e1c958561a2_key and $encrypted_7e1c958561a2_iv) in the repository settings of travis-ci.

On forks and pull requests those secure variables aren't available, so the openssl command fails

Can someone fix this?

Follow author by API from text list

I have a text file with a list of my authors, i'd like the ability to pass them to a py script and follow/verifyfollow on each for good reads.

Anyone suggest the best way to do this?

How to get all pages

I'd like to know how can I get all pages from a books search:

from goodreads import client
gc = client.GoodreadsClient('', '')
user = gc.search_books('mystery', search_field='genre')
print(user)


attribute error in deployment

Hi! I'm sorry to bother you again. I get the error message on the logs on Heroku:

2015-04-29T07:57:14.996321+00:00 app[web.1]: AttributeError: GoodreadsClient instance has no attribute 'search_books'

Yet, the GoodreadsClient instance has this attribute locally (I am able to execute my script locally).

Doing some digging, I found that when deployed, GoodreadsClient instance does not have the 'search_books' and 'find_author' instances (though the rest of the attributes work fine). I thought it may be a version error on the deployed copy on Heroku as these functions were only added recently, but both my local copy and the deployed copy of the module are up-to-date (based on the requirements.txt file I included in deployment).

TypeError: __init__() missing 1 required positional argument: 'client' - Repost

Hey sefakilic it still doesn't work. I can confirm I have books owned because this script:

from goodreads import client

api_key = "XXXXX"
api_secret = "XXXXX"
gc = client.GoodreadsClient(api_key, api_secret)
gc.authenticate()

user_id = XXXXXX
user = gc.user(user_id)
owned_books = user.owned_books()
for owned_book in owned_books:
    print(owned_book.link())

Produces this output:

Have you authorized me? (y/n)y
https://www.goodreads.com/owned_books/42981652
https://www.goodreads.com/owned_books/42981655
https://www.goodreads.com/owned_books/42981654
https://www.goodreads.com/owned_books/42981647
https://www.goodreads.com/owned_books/42981650

I am really just trying to get a list of books I have read. There might be a better way of simply accessing my "read" shelf and listing the books off there? But I don't know how to do that.

Here's my previous post:

Hey I'm not sure if this a bug or if I am doing it incorrectly. I am trying to access my owned books by doing this:

from goodreads import client

api_key = "my api key"
api_secret = "my secret"
gc = client.GoodreadsClient(api_key, api_secret)
gc.authenticate()

user_id = my good reads id
user = gc.user(user_id)
owned_books = user.owned_books()
for owned_book in owned_books:
    print(owned_book.book)

owned_book methods return errors

I'm using 0.2.4 with Django for a web app, and I'm encountering repeated errors when accessing owned_book instances.

Thus far:

owned_book.GoodreadsOwnedBook.book
owned_book.GoodreadsOwnedBook.gid
owned_book.GoodreadsOwnedBook.current_owner

All give "string indices must be integers" errors when called.

None response on - owned_books

I'm trying to implement an app that consumes the api to get all the books that a user owns, but I'm getting None response from goodreads... I don't know if it has to do with my test or something else.

Here is what I'm using to test:
from goodreads import client
key = 'xxx'
secret = 'xxx'
gc = client.GoodreadsClient(key, secret)
gc.authenticate()

Then

user = gc.user()
user.owned_books()

The response on the shell is:
INFO:requests.packages.urllib3.connectionpool:Resetting dropped connection: www.goodreads.com
DEBUG:requests.packages.urllib3.connectionpool:"GET /owned_books/user/xxx.xml?oauth_nonce=55fca771e0550da0e82fa4c043946aadf5f57626&format=xml&oauth_consumer_key=xxx&oauth_timestamp=1458051917&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token=iwZidyCR5ll4pWtdAbgUiQ&oauth_signature=G6Q4pav9%2BUU6283%2BBmagsBDDBU8%3D&page=1 HTTP/1.1" 200 None
Traceback (most recent call last):
File "", line 1, in
File "..../src/goodreads-api/goodreads/user.py", line 59, in owned_books
for d in resp['owned_books']['owned_book']]
TypeError: 'NoneType' object has no attribute 'getitem'

I intentionally putted "xxx" under the consumer_key and xxx under the user that I'm using, but I'm using the exact same string than the provided by goodreads.

I don't know if this is an issue with this library or with goodreads.

I've tested a bunch of other api points and they work. The only one that doesn't work for me is is the owned_books

no shelf api functions?

I could be mistaken, but I don't see any way to manipulate the user's shelves, (etc: adding books to, removing books from, listing, etc).
I think you can use the request function to make a raw request to Goodreads and this is what I'll most likely be using for these functions, but could we get the shelf functions? :)

parsing issue

Hi! Sorry if this is a stupid question, I new to programming and seem to be getting this error message on Windows when I try to go through the readme:

C:\Python>python2 goodreads_script.py
Traceback (most recent call last):
  File "goodreads_script.py", line 4, in <module>
    book = gc.book(1)
  File "build\bdist.win32\egg\goodreads\client.py", line 87, in book
  File "build\bdist.win32\egg\goodreads\client.py", line 57, in request
  File "build\bdist.win32\egg\goodreads\request.py", line 26, in request
  File "build\bdist.win32\egg\xmltodict.py", line 248, in parse
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 0

C:\Python>

It seems to me as though my api key is invalid? I tried resetting it but it gives the same error message. I also tried passing the wrong key to client.GoodreadsClient(), but it also gives the same error message. Edit: Nvm about that; tried it again, it gave a different error message.

Edit2: Okay, according to the error, it's something wrong with the xml that's being fed to the parser. I'm not sure how to go around this.

If you could direct me to where I messed up or what I'm missing, that would be great. :-)

goodreads_script.py was just the file I created following the readme. It goes:

from goodreads import client
gc = client.GoodreadsClient(client_key='........', client_secret='........')

book = gc.book(1)
book.title

Reviews bug

Hey man – quick q. When I try to access reviews (after authentication), this breaks (error below). I wasn't able to figure out where it was breaking at a quick glance but if you have any theories, I'd be happy to fix it and write some more thorough tests for it.

screenshot 2015-04-15 15 38 18

Shelves is not working

import os


from goodreads import client

gr_key = os.environ.get('GR_KEY')
gr_secret = os.environ.get('GR_SECRET')
gc = client.GoodreadsClient(gr_key, gr_secret)
user = gc.user(9669859)
print(user.shelves())

This throws

py good_reads.py
Traceback (most recent call last):
  File "good_reads.py", line 10, in <module>
    print(user.shelves())
  File "/home/chillaranand/.virtualenvs/p35/lib/python3.5/site-packages/goodreads/shelf.py", line 7, in __repr__
    return self.name
  File "/home/chillaranand/.virtualenvs/p35/lib/python3.5/site-packages/goodreads/shelf.py", line 11, in name
    return self._shelf_dict['@name']
KeyError: '@name'

Import Error : Client

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

The above code returns the following error:

ImportError: cannot import name client

Is there any way to fix this? Why would this show up?
Any help will be appreciated!
Thanks

Import error

Hi, I am having trouble importing. I am in a virtualenv and can import goodreads but not the client, which cannot import sessions. I have verified that it is right package, and that the path is correct. Please see exact error below:

## I can import goodreads
>>> import goodreads

## but not the client
>>> from goodreads import client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/Envs/flask/lib/python3.5/site-packages/goodreads/client.py", line 2, 
    from session import GoodreadsSession
ImportError: No module named 'session'

I am using python3, but there should not be an error with import?

No search API

search.book and search.author are provided by official Goodreads, need to implement those.

TypeError in user.shelves

Hi @sefakilic )

I appreciate the work you've done but there's a slight glitch in the package it seems.

I'm posting the output traceback, perhaps the error originates from xml dependency?

In [28]: user.reviews()
----------------------------------------------------------------
TypeError                      Traceback (most recent call last)
/Users/eklavya/anaconda/lib/python3.5/site-packages/xmltodict.py in parse(xml_input, encoding, expat, process_namespaces, namespace_separator, **kwargs)
    308     try:
--> 309         parser.ParseFile(xml_input)
    310     except (TypeError, AttributeError):

TypeError: argument must have 'read' attribute

During handling of the above exception, another exception occurred:

ExpatError                     Traceback (most recent call last)
<ipython-input-28-00cccc6e2a71> in <module>()
----> 1 user.reviews()

/Users/eklavya/anaconda/lib/python3.5/site-packages/goodreads/user.py in reviews(self, page)
     79         """Get all books and reviews on user's shelves"""
     80         resp = self._client.session.get("/review/list.xml",
---> 81                                         {'v': 2, 'id': self.gid, 'page': page})
     82         return [review.GoodreadsReview(r) for r in resp['reviews']['review']]
     83

/Users/eklavya/anaconda/lib/python3.5/site-packages/goodreads/session.py in get(self, path, params)
     52         base = "https://www.goodreads.com/"
     53         resp = self.session.get(base + path, params=params)
---> 54         return xmltodict.parse(resp.content)['GoodreadsResponse']

/Users/eklavya/anaconda/lib/python3.5/site-packages/xmltodict.py in parse(xml_input, encoding, expat, process_namespaces, namespace_separator, **kwargs)
    309         parser.ParseFile(xml_input)
    310     except (TypeError, AttributeError):
--> 311         parser.Parse(xml_input, True)
    312     return handler.item
    313

ExpatError: syntax error: line 1, column 0

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.