Exemple #1
0
def make_client():
    """Create a client object"""
    key, secret = apikey.key, apikey.secret
    client = GoodreadsClient(key, secret)
    client.authenticate(apikey.oauth_access_token,
                        apikey.oauth_access_token_secret)
    return client
Exemple #2
0
def make_client():
    """Create a client object"""
    key, secret = apikey.key, apikey.secret
    client = GoodreadsClient(key, secret)
    client.authenticate(apikey.oauth_access_token,
                        apikey.oauth_access_token_secret)
    return client
Exemple #3
0
 def test_many_authors(self):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     book = client.book('18774683')
     assert len(book.authors) == 2
     assert isinstance(book.authors[0], GoodreadsAuthor)
Exemple #4
0
def create_book(book_id, rating=None):
    resp = GoodreadsClient.book(book_id)

    book = BookSchema().load(resp)
    book.save()

    resp_author = resp["authors"]["author"]
    if type(resp_author) != list:
        resp_author = [resp_author]

    for author in resp_author:
        a = AuthorSchema().load(author)
        a.save()
        book.authors.add(a)

    book.series = try_get_series(resp["work"][0]["id"])
    book.series.save()

    resp_publisher = resp["publisher"]
    if resp_publisher:
        (pub, created) = Publisher.objects.get_or_create(name=resp_publisher)
        book.publisher = pub

    if rating is not None and rating != 0:
        book.rating = rating

    book.save()
def connect(key=None, secret=None, enabled=True):
    global _client

    if not enabled or not key or not secret:
        _client = None
        return

    if _client:
        # make sure the configuration has not changed since last we used the client
        if _client.client_key != key or _client.client_secret != secret:
            _client = None

    if not _client:
        _client = GoodreadsClient(key, secret)
Exemple #6
0
def books_read_by_user():
    results = []

    page = 1
    while True:
        resp = GoodreadsClient.shelf(settings.GOODREADS_USER_ID, "read", page)
        results += resp["review"]

        if int(resp["@end"]) >= int(resp["@total"]):
            break

        page += 1

    return results
Exemple #7
0
def try_get_series(work_id):
    try:
        series = GoodreadsClient.series(work_id)
        series = series["series_work"]

        # FIXME: probably shouldn't just select the first option automatically
        # if there are multiple choices...
        if type(series) == list:
            series = series[0]

        return SeriesSchema().load(series["series"])
    except:
        uncategorized = Series.objects.get(id=0)
        return uncategorized
Exemple #8
0
def search(request):
    query = request.GET.get("query")
    if query is not None:
        page = request.GET.get("page", 1)
        context = {
            "results": GoodreadsClient.search(query, page),
            "read": {b.id
                     for b in Book.objects.all()},
            "page": page,
        }
    else:
        context = {}

    return render(request, "web/search.html", context=context)
Exemple #9
0
 def setup_class(cls):
     client = GoodreadsClient('nTRaECtlyOjSmjJnLKRaiw', 'hCXp9GKlAe3sk1QIj0jXLF4UGLt9vfj54hDAfzHY')
     #client.authenticate(apikey.oauth_access_token,
      #                   apikey.oauth_access_token_secret)
     cls.book = client.book('11870085')
Exemple #10
0
 def setup_class(cls):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     cls.author = client.author('64941')
Exemple #11
0
 def setup_class(cls):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     cls.owned_book = client.owned_book('43018920')
Exemple #12
0
 def setup_class(cls):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     cls.comments = client.list_comments('user', '1')
Exemple #13
0
 def setup_class(cls):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     cls.events = client.list_events(55408)
     cls.event = cls.events[0]
Exemple #14
0
 def setup_class(cls):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     cls.comments = client.list_comments('user', '1')
     cls.comment = cls.comments[0]
Exemple #15
0
 def setup_class(cls):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     cls.book = client.book('11870085')
Exemple #16
0
 def setup_class(cls):
     cls.client = GoodreadsClient(apikey.key, apikey.secret)
     cls.client.authenticate(apikey.oauth_access_token,
                             apikey.oauth_access_token_secret)
Exemple #17
0
 def setup_class(cls):
     client = GoodreadsClient(apikey.key, apikey.secret)
     client.authenticate(apikey.oauth_access_token,
                         apikey.oauth_access_token_secret)
     cls.group = client.group(1)