Ejemplo n.º 1
0
def get_cover(title):
    client = gr.Client(developer_key='hqeLOWfIts8XH3EBK8eiJA')
    books = client.search_book(title)
    if int(dict(books).get('total-results')) == 0:
        return "http://213.177.28.84/covers.svc?h=140&rid=30565&sourceType=local&t=m&w=99"
    elif int(dict(books).get('total-results')) == 1:
        results = dict(dict(books).get('results')).get('work')
        id = dict(dict(dict(results).get('best_book')).get('id')).get('#text')
        book = client.Book.show(id)
        keys_wanted = ['link']
        book = {k: v for k, v in book.items() if k in keys_wanted}
        book_url = BeautifulSoup(
            requests.get(book.get('link')).text, 'html.parser')
        img = book_url.find('img', {'id': 'coverImage'}).get("src")
        return img
    else:
        results = list(dict(dict(books).get('results')).get('work'))[0]
        title_r = str(dict(dict(results).get('best_book')).get('title'))
        if (title == title_r):
            id = dict(dict(
                dict(results).get('best_book')).get('id')).get('#text')
            book = client.Book.show(id)
            keys_wanted = ['link']
            book = {k: v for k, v in book.items() if k in keys_wanted}
            book_url = BeautifulSoup(
                requests.get(book.get('link')).text, 'html.parser')
            img = book_url.find('img', {'id': 'coverImage'}).get("src")
        else:
            img = "http://213.177.28.84/covers.svc?h=140&rid=30565&sourceType=local&t=m&w=99"
        return img
Ejemplo n.º 2
0
class GoodReadService:

    client = gr.Client(developer_key=settings.GOODREAD_API_KEY)

    @classmethod
    def get_book_by_id(cls, book_id):
        return cls.client.Book.show(book_id)

    @classmethod
    def search_book(cls, q, field='title'):
        books = cls.client.search_book(q, field)
        return books

    @classmethod
    def get_reviews_by_book_id(cls, book_id):
        book = cls.client.Book.show(book_id)
        review_widget = book['reviews_widget']
        review_holder = BeautifulSoup(review_widget, 'html.parser')
        review_url = review_holder.find('iframe')
        r = requests.get(review_url['src'])
        response_html = r.text
        review_page = BeautifulSoup(response_html, 'html.parser')
        all_div = review_page.findAll('div')
        reviews = []
        for div in all_div:
            if 'gr_review_text' in div.get('class', []):
                reviews.append(div)
        return reviews
def get_the_link(isbn_number):
    client = gr.Client(developer_key='fGkJVZsWA7At7eDPqUec4A')
    book = client.Book.show_by_isbn(isbn=isbn_number)
    keys_wanted = ['id', 'title', 'isbn', 'reviews_widget']
    reduced_book = {k:v for k, v in book.items() if k in keys_wanted}
    widget = reduced_book['reviews_widget']
    link = get_the_link_from_widget(widget)
    return link
Ejemplo n.º 4
0
def get_book_genres(book_title):
    book_id = get_book_id(book_title)
    client = gr.Client(developer_key='<q5QJR1BpwdBHs7SLjH0mw>')
    book = client.Book.show(book_id)
    x = book['popular_shelves']
    res = set()
    for elem in x['shelf']:
        res.add(elem['@name'])
    return res
Ejemplo n.º 5
0
def get_buy_link(book_title):
    book_id = get_book_id(book_title)
    client = gr.Client(developer_key='<q5QJR1BpwdBHs7SLjH0mw>')
    book = client.Book.show(book_id)
    isbn = book['isbn']
    if isbn is None:
        return None
    amz = "http://www.amazon.com/dp/{}".format(isbn)
    return amz
Ejemplo n.º 6
0
def get_books_of_author(auth_id):
    client = gr.Client(developer_key='q5QJR1BpwdBHs7SLjH0mw')
    list_of_books = []
    temp = client.Author.books(auth_id)['book']
    for i in range(len(temp)):
        if 'average_rating' in temp[i] and float(
                temp[i]['average_rating']) > 4:
            list_of_books.append(temp[i]['title'])
    return list_of_books
Ejemplo n.º 7
0
    def __init__(self, context, page=None):
        self.client = context.obj['client']
        self.config = context.obj['config'].get('booklist_info')
        self.logger = context.obj['logger']
        self.gr_client = gr.Client(developer_key=self.config.get('goodreads_api_token'))

        self.page = self.config.get('page')
        if page:
            self.page = page

        table_data = self._get_db_data()
        self._process_table_data(table_data)
Ejemplo n.º 8
0
def get_book_author(book_title):
    book_id = get_book_id(book_title)
    client = gr.Client(developer_key='<q5QJR1BpwdBHs7SLjH0mw>')
    book = client.Book.show(book_id)
    authors = book['authors']['author']
    res = []
    for elem in authors:
        if elem:
            try:
                res.append(escape_single_quote(elem['name']))
            except TypeError as e:
                res.append(escape_single_quote(authors['name']))
                break
    return res
Ejemplo n.º 9
0
def get_books_of_Author(book_title):
    client = gr.Client(developer_key='q5QJR1BpwdBHs7SLjH0mw')
    book = client.Book.title(book_title)
    books_to_every_Author = []
    if type(book['authors']['author']) == collections.OrderedDict:
        auth_id = book['authors']['author']['id']
        #random_book = random.randint(0, len(client.Author.books(auth_id)['book']) - 1)
        #book_to_recommend = client.Author.books(auth_id)['book'][random_book]['title']
        books_to_every_Author.append(get_books_of_author(auth_id))
        return books_to_every_Author
    elif type(book['authors']['author']) == list:
        # random_author=random.randint(0,len(book['authors']['author'])-1)
        for i in range(len(book['authors']['author'])):
            books_to_every_Author.append(
                get_books_of_author(book['authors']['author'][i]['id']))
        return books_to_every_Author
Ejemplo n.º 10
0
def get_recommendation_author(book_title):
    client = gr.Client(developer_key='q5QJR1BpwdBHs7SLjH0mw')
    book = client.Book.title(book_title)
    if type(book['authors']['author']) == collections.OrderedDict:
        auth_id = book['authors']['author']['id']
        random_book = random.randint(
            0,
            len(client.Author.books(auth_id)['book']) - 1)
        book_to_recommend = client.Author.books(
            auth_id)['book'][random_book]['title']
        return escape_single_quote(book_to_recommend)
    elif type(book['authors']['author']) == list:
        random_author = random.randint(0, len(book['authors']['author']) - 1)
        # for i in range(len(book['authors']['author'])):
        #     print(book['authors']['author'][i]['id'])
        auth_id = book['authors']['author'][random_author]['id']
        random_book = random.randint(
            0,
            len(client.Author.books(auth_id)['book']) - 1)
        book_to_recommend = client.Author.books(
            auth_id)['book'][random_book]['title']
        return escape_single_quote(book_to_recommend)
Ejemplo n.º 11
0
def goodreads(grid):
    """Add book details from Goodreads API.

    """
    # print(f"scraping goodreads data from {grid}")
    key = "cQudYNjfcBYXcVj9w9zA"
    client = gr.Client(developer_key=key)
    result = client.Book.show(grid)
    dic = {}

    if result["series_works"]:

        series = result["series_works"]["series_work"]
        series = [series] if not isinstance(series, list) else series
        dic["series"] = [
            s["series"]["title"].replace("'", "’") for s in series
        ]
        dic["position_in_series"] = [s["user_position"] for s in series]

    dic["goodreads_score"] = float(result["average_rating"])
    dic["goodreads_popularity"] = int(result["ratings_count"])
    # print(f"goodreads data {dic}")
    return dic
Ejemplo n.º 12
0
 def goodreads_books(self, request, pk=None):
     client = gr.Client(developer_key='FtV2JkeEaiobnja5s890Q')
     name = self.request.query_params['name']
     response = client.search_book(q=name)
     books = []
     for r in response['results']['work']:
         book = {
             'average_rating':
             r['average_rating'],
             'original_publication_year':
             r['original_publication_year']['#text'],
             'id':
             r['best_book']['id']['#text'],
             'title':
             r['best_book']['title'],
             'author':
             r['best_book']['author']['name'],
             'img':
             r['best_book']['image_url'],
             'small_img':
             r['best_book']['small_image_url'],
         }
         books.append(book)
     return Response(list(books))
sns.set_context('talk')
most_books = df.groupby('authors')['title'].count().reset_index().sort_values(
    'title', ascending=False).head(10).set_index('authors')
plt.figure(figsize=(15, 10))
ax = sns.barplot(most_books['title'], most_books.index, palette='icefire_r')
ax.set_title("Top 10 authors with most books")
ax.set_xlabel("Total number of books")
for i in ax.patches:
    ax.text(i.get_width() + .3,
            i.get_y() + 0.5,
            str(round(i.get_width())),
            fontsize=10,
            color='k')

client = gr.Client(developer_key='fgwnppR6Q1wpFt0n6umUQ'
                   )  #If possible, please get your own? :)

# Creating a function to get book details from the ISBN 13 value.


#Alternate scraping solution, when both the API(s) fails
def html(isbn):
    url = 'https://isbndb.com/book/' + isbn
    article = Article(url)
    #article = 'https://isbndb.com/book/9780450524684'
    article.download()
    article.parse()
    ar = article.html
    ar = ar[9300:9900]
    return ar
Ejemplo n.º 14
0
bid = []
for li in list_href:
    s = li.split('show/')
    if s[1].find('-')==-1:
        bid.append(s[1].split('.')[0])
    else:
        bid.append(s[1].split('-')[0])


# In[73]:



#

client = gr.Client(developer_key=goodreads_key)
book_list = []

for i in bid:
    book = client.Book.show(i)
    time.sleep(1)
    print(i)
    try:
        i13 = book['isbn13']
    except:
        i13 = None
    try:
        title = book['title']
    except:    
        title = None
    try:
Ejemplo n.º 15
0
from flask import Flask, render_template,request,redirect,url_for,session
import sqlite3
import goodreads_api_client as gr
import os
import requests
from xml.etree import ElementTree
import shutil

current = ""
adminCh = False
DevKey = 'UvqPf2fGbH2YoWaetp1bA'
client = gr.Client(developer_key = DevKey)

app = Flask(__name__)

app.secret_key = '\xf0\xa5\x9ewe6\x82RU\x8b\t\x0b\xb6\xcc\xf8\xb2\xdb\x02\x83\xab\x0f\x13\x15'

conn = sqlite3.connect("Users.db")
c = conn.cursor()

c.execute("CREATE TABLE IF NOT EXISTS users (first_name text NOT NULL,last_name text NOT NULL,email text PRIMARY KEY NOT NULL, password text NOT NULL, username text NOT NULL)")
c.close()
conn.close()

@app.route('/',methods=['GET', 'POST'])
def index():
    conn = sqlite3.connect("Users.db")
    c = conn.cursor()
    if request.method == 'POST':
        if request.form.get('first_name'):
            fname = request.form['first_name']
Ejemplo n.º 16
0
import os, sys ,json, collections,requests
from flask import Flask, request,jsonify,g
from pymessenger import Bot
#from goodreads import client

import goodreads_api_client as gr
from bs4 import BeautifulSoup


from tokens import *
#from app import *


client = gr.Client(developer_key=GOODREADS_DEVELOPERKEY)
bot = Bot(PAGE_ACCESS_TOKEN)




class GoodReads:

    @classmethod
    def Retrieve_book_id(cls,index,booklist):
        goodread_id=str(booklist[int(index)-1]['id'])
        return goodread_id

    @classmethod
    def searchbytitle(cls,title,User_id):
         booktitles = []
         books = client.search_book(title, 'title')
Ejemplo n.º 17
0
import traceback
import goodreads_api_client as gr
import json
import time
import os

client = gr.Client(developer_key='DxSHlcbnweXsSqfuGMj2eQ')

book_files= open('./dataset.txt', 'r')
author_files = open('./dataset-author.txt', 'a')
known = set()
for line in book_files.readlines():
    print(line)
    obj = json.loads(line)
    # print(obj['authors']['author'])
    for author in obj['authors']['author']:
        if  int(author['id']) in known:
            continue
        known.add(int(author['id']))
        au = gr.Author.show(author['id'])
        keys_wanted = ['name', 'image_url', 'about', 'gender', 'born_at', 'died_at', 'hometown']
        mau = {k:v for k,v in au.items() if k in keys_wanted}
        author_files.write(json.dumps(mau)+'\n')
        
Ejemplo n.º 18
0
import glob
import csv
import markdown
from lxml import etree
import json
import goodreads_api_client as gr
from goodreads import client
import time

grClient = gr.Client(developer_key='3vSHhFDbwPDYCNdXZ8D7g')
gc = client.GoodreadsClient('3vSHhFDbwPDYCNdXZ8D7g',
                            'y7KD7UFxswI7SLEJhtYjO6brGzvkS3MsMcv9fBNdZ4')

data = {}

count = 0

for name in glob.glob("*.csv"):
    X = name.split('.')[0]
    data[X] = []
    with open(name) as f:
        dic = csv.DictReader(f)
        for line in dic:
            doc = etree.fromstring(markdown.markdown(str(line)))
            linkObj = doc.xpath('//a')[0]
            link = linkObj.get('href')
            starts = ('https://www.goodreads.com/book/show/',
                      'http://www.goodreads.com/book/show/',
                      'https://www.goodreads.com/series/',
                      'http://www.goodreads.com/series/',
                      'www.goodreads.com/book/show/')
Ejemplo n.º 19
0
def get_book_title_from(book_title):
    book_id = get_book_id(book_title)
    client = gr.Client(developer_key='<q5QJR1BpwdBHs7SLjH0mw>')
    book = client.Book.show(book_id)
    return book['title']
Ejemplo n.º 20
0
def get_description(book_title):
    client = gr.Client(developer_key='q5QJR1BpwdBHs7SLjH0mw')
    book = client.Book.title(book_title)
    description = cleanhtml(book['description'])
    return escape_single_quote(description)
Ejemplo n.º 21
0
def get_book_id(book_title):
    client = gr.Client(developer_key='<q5QJR1BpwdBHs7SLjH0mw>')
    book = client.Book.title(book_title)
    return book['id']
Ejemplo n.º 22
0
from urllib.parse import urlencode
import os

import goodreads_api_client as gr
import oauth2 as oauth

from dotenv import load_dotenv
import xmltodict

from web.services.goodreads_service.read import load_entity
from web.services.goodreads_service.types import GoodReadsEntityType

load_dotenv()
GOODREADS_KEY = os.getenv('GOODREADS_KEY')
GOODREADS_SECRET = os.getenv('GOODREADS_SECRET')
gr_client = gr.Client(developer_key=GOODREADS_KEY)


def parse_book(gr_id: str):
    book = gr_client.Book.show('18883652')  # Permutation City
    # book = gr_client.Book.show('1128434')  # The Witcher
    # keys_wanted = ['id', 'title', 'isbn']
    # reduced_book = {k:v for k, v in book.items() if k in keys_wanted}
    print(book['title'])
    print(book['description'])

    series_id = book['series_works']['series_work']['series']['id']
    series = gr_client.Series.show(series_id)  # Subjective Cosomology
    print(series['title'])
    print(series['description'])
Ejemplo n.º 23
0
            data = r.json()
            return data
    except Exception:
        return None


def get_valid_quotes(quotes, author, book_title):
    final_quotes = []
    for quote in quotes:
        if check_quote_valid(quote, author, book_title):
            final_quotes.append(quote["quote"])
    return final_quotes


# client = gr.Client(developer_key=api_key, developer_secret=api_secret)
client = gr.Client(developer_key=api_key)
books = []

with open(data_in, 'r', newline='') as in_file, open(data_out + ".json",
                                                     'w',
                                                     newline='') as out_file:
    reader = csv.reader(in_file)
    row0 = next(reader)

    for row in reader:
        print(row[bookID_row])
        print(index)

        # Get info of the book
        try:
            book = client.Book.show(row[bookID_row])  # 1128434 - 2832909
Ejemplo n.º 24
0
from rest_framework import viewsets, status
from django.contrib.auth.models import User
from rest_framework.permissions import BasePermission, IsAuthenticated
from rest_framework.decorators import action
from rest_framework.response import Response

from . import models, serializers

import goodreads_api_client as gr
client = gr.Client(developer_key='FtV2JkeEaiobnja5s890Q')


class BooksModelViewSet(viewsets.ModelViewSet):
    queryset = models.Book.objects.all()
    serializer_class = serializers.BookSerializer

    @action(methods=['GET'], detail=False, url_path='search')
    def goodreads_books(self, request, pk=None):
        client = gr.Client(developer_key='FtV2JkeEaiobnja5s890Q')
        name = self.request.query_params['name']
        response = client.search_book(q=name)
        books = []
        for r in response['results']['work']:
            book = {
                'average_rating':
                r['average_rating'],
                'original_publication_year':
                r['original_publication_year']['#text'],
                'id':
                r['best_book']['id']['#text'],
                'title':
Ejemplo n.º 25
0
print('Executing file name: ' + exec_path_bare)

try:
    import config
    API_KEY, API_SECRET = config.access_keys(exec_path_bare)
    print('Importing config file successful!')
    print('-----')
except ImportError as import_err:
    print('ERROR: ' + str(import_err))
    print('Add correct config.py file with API Keys then try again')
    quit()  #stop running the code if no config.py file found

usrIn = input('Run the goodreads API or webscrape? [1 for API]: ')

if usrIn == str(1):
    client = gr.Client(developer_key=API_KEY)
    #Example: get 'The Last Wish' to see what parameters show up
    book = client.Book.show('1128434')
    print(book)

    print('sleeping zzz...')
    time.sleep(1)  #stop for 1s (avoid API violation)

    #Show a ~random~ specific review info
    review = client.Review.show('3805')
    print(review)

    print('sleeping zzz...')
    time.sleep(1)  #stop for 1s (avoid API violation)

    #Look at the book title?
Ejemplo n.º 26
0
import goodreads_api_client as gr
import os

key = os.environ['GOODREADS_API_KEY']
client = gr.Client(developer_key=key)
Ejemplo n.º 27
0
Idea: take first 1000 books, get info on average rating, 
text_reviews_count, ratings_counts ---> predict average rating

Question: are unpopular books worse or better??
We want an answer


@author: macbookair
"""

from matplotlib import pyplot as plt
import goodreads_api_client as gr
import random as rd

client = gr.Client(developer_key='IEI0W7ERS2AugD2He1Zug')

books = []

#manyRands = [i for i in range(200)]
#print(manyRands)

for i in range(21, 2000):
    try:
        book = client.Book.show(str(i))
        books.append(book)
    except:
        continue

keys = [
    'id', 'title', 'isbn', 'average_rating', 'ratings_count',
import pandas as pd
import isbnlib
from newspaper import Article
import matplotlib.pyplot as plt
plt.style.use('ggplot')
from progressbar import ProgressBar
import re
import goodreads_api_client as gr

goodreads = pd.read_csv(
    '/Users/ngohoanganh/Desktop/Goodreads Kaggle project/books.csv',
    error_bad_lines=False)

client = gr.Client(developer_key='fgwnppR6Q1wpFt0n6umUQ'
                   )  #API given in the reference notebook on Kaggle


def html(isbn):
    url = 'https://isbndb.com/book/' + isbn
    article = Article(url)
    article.download()
    article.parse()
    ar = article.html
    ar = ar[9300:9900]
    return ar


def reg(l):
    return re.search(r'(\b\d{4})\b', l).groups()[0]

Ejemplo n.º 29
0
from goodreads import client
import goodreads_api_client as gr
import colorama # Чтобы было прикольней и весело
from goodreads import client
import googletrans
import goodreads_api_client as gr

from db_con import *
from colorama import Fore
colorama.init()

client = gr.Client(developer_key='Y6KLU6ejpge4GENfZw1Z8w')

def Get_Info(data):
    list_translate=select(f"select name from books where id={data['id']}")
    for name_book in list_translate:
        return {**data, **{'Ru_name':name_book[0]}}

print(Fore.BLUE)
book_input = int(input("Введи айди: "))
book = client.Book.show(book_input)
keys_wanted = ['id', 'title', 'isbn']
reduced_book = {k:v for k, v in book.items() if k in keys_wanted}
reduced_rus_book = (Get_Info(reduced_book))


print(Fore.RED + reduced_book['title'] + Fore.GREEN + '\n' + 'Локализация: ' + reduced_rus_book['Ru_name'])
import goodreads_api_client as gr
import config as config

client = gr.Client(developer_key=config.goodreads_access["key"],
                   developer_secret=config.goodreads_access["secret"],
                   base_url="https://www.goodreads.com")


# client.authorize()
def getToRead():
    shelves = client.Shelf.list("94530768-shubham-gondane")
    to_read_dict = client.Review.list("94530768", "to-read", 50)
    books_list = []
    for book in to_read_dict["reviews"]["review"]:
        title = book["book"]["title"]
        authors_data = book["book"]["authors"]
        author = authors_data["author"]["name"]
        books_list.append([str(title), str(author)])
    return books_list