Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

user functions not working. #34

Open
ghost opened this issue Dec 3, 2019 · 3 comments
Open

user functions not working. #34

ghost opened this issue Dec 3, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 3, 2019

Jess,

I apologize if I am just missing something as a new python user.
Your documentation for user:
https://betterreads.readthedocs.io/en/latest/user.html

I can use the "user" example and get user.user and user.user_name to work however nothing below your sample code works.
list_groups, owned_books, shelves, etc do not work.

here is test commands( name, link work, but shelves and list_groups do not):

from betterreads import client
gc = client.GoodreadsClient('key', 'secret key')
user = gc.user(user_id=10961320)
user.name
'Shane Phillips'
user.shelves
Traceback (most recent call last):
File "", line 1, in
TypeError: repr returned non-string (type int)
user.link
'https://www.goodreads.com/user/show/10961320-shane-phillips'
user.list_groups
Traceback (most recent call last):
File "", line 1, in
TypeError: repr returned non-string (type int)

I also tried assigning list and printing

s=user.shelves
print(s)
Traceback (most recent call last):
File "", line 1, in
TypeError: repr returned non-string (type int)

and

s=user.shelves
for items in s:
... print(items)
...
Traceback (most recent call last):
File "", line 1, in
TypeError: 'method' object is not iterable

@oneross

This comment has been minimized.

@oneross
Copy link

oneross commented Apr 24, 2020

Big Caveat

I have no idea how the client and sessions management is really working so could totally be something I'm doing wrong, but @shanephillipsgithub is having the same issue so at a minimum we could flesh out the documents and examples. I'll cut a new env to clear away the pip installed version and clone a dev version to play around a little over the next few days.

Same Issue

Just rediscovered at least a similar issue, with user.owned_books. Simple script to illustrate - authentication works fine.

from secret import MyGoodreadsApp as app
from betterreads import client

gc = client.GoodreadsClient(app['api_key'], app['api_secret'])
gc.authenticate()

user = gc.user(app['user_id'])

print(user.owned_books)

results in

/usr/local/Caskroom/miniconda/base/envs/readwise/lib/python3.8/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    682     """A pprint that just redirects to the normal repr function."""
    683     # Find newlines and replace them with p.break_()
--> 684     output = repr(obj)
    685     lines = output.splitlines()
    686     with p.group():

TypeError: __repr__ returned non-string (type int)

Research

A little more digging. user.owned_books returns a method instead of a list.

x = user.owned_books
type(x)
  method

In the examples that are working (for example, user.name, user.small_image_url) all of the methods have the @property decorator in betterreads/user.py, the ones that aren't working (owned_books, list_groups, shelves) do not.

Just for giggles, I tried y = user.owned_books() to evaluate, and this time I'm getting an error suggesting that the response from _client.request is None.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-252285cf8b2d> in <module>
----> 1 y = user.owned_books()

/usr/local/Caskroom/miniconda/base/envs/readwise/lib/python3.8/site-packages/betterreads/user.py in owned_books(self, page)
     67                 "owned_books/user", {"page": page, "format": "xml", "id": self.gid}
     68             )
---> 69             owned_books_resp = resp["owned_books"]["owned_book"]
     70             # If there's only one owned book returned, put it in a list.
     71             if type(owned_books_resp) == collections.OrderedDict:

TypeError: 'NoneType' object is not subscriptable

To Do:

  • Add failing unit tests (isinstance of list assertions for owned_books, etc.) to user_test.py
  • Expand tests fixtures if required
  • Fix property decorators
  • Evaluate abstraction of GoodReadOwnedBooks to match GoodreadsOwnedBook (don't see a lot of value at present)

@oneross
Copy link

oneross commented Apr 24, 2020

@shanephillipsgithub - I'm still having issues w/ user.owned_books (which is what I need to experiment with - I'm looking to export my highlights and notes by way of the books I own), but just invoking list_groups and shelves as functions/methods instead of properties might work for you in the meantime:

In [1]: from secret import app

In [2]: from betterreads import client

In [3]: gc = client.GoodreadsClient(app['api_key'], app['api_secret'])

In [4]: gc.authenticate()
Have you authorized me? (y/n)y

In [5]: user = gc.user(app['user_id'])

In [6]: print(user.list_groups())
[]

In [7]: print(user.shelves())
[read, currently-reading, to-read, to-read-nook, abandoned, audio-book, ebook, recommendations, unread-books-i-own]

Note the parentheses in user.shelves() and user.list_groups(). Hope this helps!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant