Ejemplo n.º 1
0
def get_name(request):
    if request.method == 'POST':
        form = NameForm(request.POST)
        if form.is_valid():
            isbn = str(form.cleaned_data['isbn'])
            SERVICE = 'default'
            my_dict = meta(isbn, SERVICE)
            print(my_dict)
            obj = form.save(commit=False)
            if (desc(isbn)) is None:
                pass
            else:
                my_dict['desc'] = (desc(isbn))
                obj.desc = my_dict['desc']
            if (cover(isbn)) is None:
                pass
            else:
                my_dict['covers'] = (cover(isbn))
                obj.thumbnail_small = my_dict['covers']['smallThumbnail']
                obj.thumbnail = my_dict['covers']['thumbnail']

            obj.isbn = my_dict['ISBN-13']
            obj.title = my_dict['Title']
            obj.authors = my_dict['Authors'][0]
            obj.publisher = my_dict['Publisher']
            obj.year = my_dict['Year']
            obj.save()
            return redirect("book:index")
    else:
        form = NameForm()
    return render(request, 'name.html', {'form': form})
Ejemplo n.º 2
0
 def isbnlib(self,ISBN):
     import isbnlib
     book = {}
     formatter = isbnlib.registry.bibformatters['json']
     try:
         content = (isbnlib.meta(str(ISBN)))
     except:
         # Try googleAPIs?
         book = self.googleapi(ISBN)
         return book
     book['publisher'] = '' # These may not exist in the results
     book['city'] = ''
     book['language'] =  content['Language']
     book['edited'] = ''
     try: book['edited'] = content['Edited']
     except: pass
     
     book['isbn'] = ISBN
     book['title'] = content['Title']
     book['authors'] = ', '.join(content['Authors'])
     DEBUG(book['authors'])
     book['year'] = content['Year']
     book['publisher'] = content['Publisher'] 
     book['abstract']  = isbnlib.desc(str(ISBN)).replace('\n',' ')
     book['type'] = 'book'
     return book
Ejemplo n.º 3
0
def update_details():
    global ISBN13
    book = input_box.value
    book_meta = isbnlib.meta(book)
    description = isbnlib.desc(book)
    title = book_meta["Title"]
    author = book_meta["Authors"][0]
    year = book_meta["Year"]
    ISBN13 = book_meta["ISBN-13"]
    details = Window(app, title=title + " " + author, width=700, layout="grid")
    Publication_Title = Text(details,
                             text="Book Title: " + title,
                             grid=[0, 1],
                             align="left")
    Author_Details = Text(details,
                          text="Author(s): " + author,
                          grid=[0, 2],
                          align="left")
    Publication_Year = Text(details,
                            text="Year of publication: " + year,
                            grid=[0, 3],
                            align="left")
    ISBN13Data = Text(details,
                      text="ISBN-13: " + ISBN13,
                      grid=[0, 4],
                      align="left")
    Description = Text(details,
                       text="Description: " + description,
                       grid=[0, 5],
                       align="left")
    Visit_Amazon = PushButton(details,
                              text="Visit Amazon",
                              command=openAmazon,
                              grid=[0, 8],
                              align="left")
Ejemplo n.º 4
0
def isbn_lookup(isbn: str):
    """
    Tool that uses isbnlib to look up information for the given ISBN.

    :param isbn: ISBN in string format, as ISBN can also have some letters and dashes
    :return: Dict with data, or None
    """
    try:
        meta_info = isbnlib.meta(isbn)
        desc = isbnlib.desc(isbn)
        cover = isbnlib.cover(isbn)

        try:
            meta_info['img'] = cover['thumbnail']
        except (TypeError, KeyError):
            meta_info['img'] = None

        return {
            'meta': meta_info,
            'desc': desc,
            'cover': cover,
        }

    except NoDataForSelectorError:
        return None
Ejemplo n.º 5
0
 def isbnlib(self,ISBN):
     import isbnlib
     book = {}
     formatter = isbnlib.registry.bibformatters['json']
     try:
         content = (isbnlib.meta(str(ISBN)))
     except:
         # Try googleAPIs?
         book = self.googleapi(ISBN)
         return book
     book['publisher'] = '' # These may not exist in the results
     book['city'] = ''
     book['language'] =  content['Language']
     book['edited'] = ''
     try: book['edited'] = content['Edited']
     except: pass
     
     book['isbn'] = ISBN
     book['title'] = content['Title']
     book['authors'] = ', '.join(content['Authors'])
     DEBUG(book['authors'])
     book['year'] = content['Year']
     book['publisher'] = content['Publisher'] 
     book['abstract']  = isbnlib.desc(str(ISBN)).replace('\n',' ')
     book['type'] = 'book'
     return book
Ejemplo n.º 6
0
  def getBookInfo(self, bookCode):
    book = isbnlib.meta(bookCode)

    # Add a description, if it's available and if the book was recovered
    if book:
      try:
        book['Description'] = isbnlib.desc(ISBN)
      except:
        book['Description'] = "N/A"

    return book
Ejemplo n.º 7
0
def info_search():
    search = str(request.vars.search)
    json_result = isbnlib.goom(search)
    data = json.dumps(json_result)
    search_return = []
    for book in json_result:
        temp = dict(book)
        temp['cover'] = isbnlib.cover(book['ISBN-13'])
        temp['desc'] = isbnlib.desc(book['ISBN-13'])
        temp['isbn'] = temp.pop('ISBN-13') #intercept and rename isbn to valid ractive
        #could include more information in search here
        search_return.append(temp)
    return response.json(search_return)
Ejemplo n.º 8
0
def info_search():
    search = str(request.vars.search)
    json_result = isbnlib.goom(search)
    data = json.dumps(json_result)
    search_return = []
    for book in json_result:
        temp = dict(book)
        temp['cover'] = isbnlib.cover(book['ISBN-13'])
        temp['desc'] = isbnlib.desc(book['ISBN-13'])
        temp['isbn'] = temp.pop(
            'ISBN-13')  #intercept and rename isbn to valid ractive
        #could include more information in search here
        search_return.append(temp)
    return response.json(search_return)
Ejemplo n.º 9
0
def isbn_info(request):
    isbn = request.GET.get('isbn', '')
    data = {}
    if isbnlib.notisbn(isbn):
        return JsonResponse(data, status=400)
    description = isbnlib.desc(isbn)
    if description:
        data.update({'description': description})
    try:
        metadata = isbnlib.meta(isbn, 'isbndb')
    except Exception:
        metadata = {}
    data.update({'meta': metadata})
    return JsonResponse(data)
Ejemplo n.º 10
0
async def desc(ctx, isbn: str):
    """Show a short description for a book.

	Args:
		isbn: ISBN number of the book you'd like the description for.

	"""
    if await channel_check(ctx):
        description = isbnlib.desc(isbn)
        if description:
            await respond(
                ctx, ["Here's a brief description of the book:", description])
        else:
            await respond(ctx, [
                "Sorry, it doesn't look like we could find a description of that book "
                + random.choice(SAD_EMOJI)
            ])
Ejemplo n.º 11
0
def get_data(ISBN):
    # global synopsis
    '''
    On récupère les données d'un livre sur google Books
    (Titre, Auteur(s), synopsis, Editeur, date de plublication, image de couverture)
    openl,goob
    '''
    book = isbnlib.meta(
        ISBN
    )  #on récupère les informations suivantes : Titre, Auteur(s), Editeur, date de plublication, langue
    synopsis = isbnlib.desc(ISBN)  #on récupère la description du livre
    url = isbnlib.cover(ISBN)  #on récupère le lien de l'image de couverture
    if url == {}:  #si on n'a pas récupéré d'image, on applique l'image par défaut
        img = 'img/no_img.jpg'
    else:
        url = url['thumbnail']
        img = write_img(url, ISBN)  #on écrit l'image

    return book, synopsis, img  #on retourne les informations obtenues
Ejemplo n.º 12
0
def isbn_to_book_desc(isbn):
    book = meta(isbn)
    description = desc(isbn)
    image = f"[img[http://covers.openlibrary.org/b/isbn/{isbn}-L.jpg]]"

    title = book["Title"]
    author = book["Authors"]
    year_published = book["Year"]

    tiddler_title = f'"{title}"'
    created = f'"{current_time.strftime(fmt)}00000"'
    modified = f'"{current_time.strftime(fmt)}00001"'
    text = f'"{title} by {author}\\n\\nPublished: {year_published}\n\n{image}"'
    tags = f'"Watched/Listened/Read"'
    start = '[{'
    end = '}]'
    type = '"text/vnd.tiddlywiki"'

    print(text)
Ejemplo n.º 13
0
def return_data(ISBN):
    try:
        data = isbnlib.meta(ISBN)
        print('data')
    except:
        data = {
            'ISBN-13': 'Vide',
            'Title': 'Vide',
            'Authors': ['Vide'],
            'Language': 'Vide',
            'Publisher': 'Vide',
            'Year': 'Vide'
        }
    try:
        data['synopsis'] = isbnlib.desc(ISBN)
        print('synopsis')
    except:
        data['synopsis'] = 'Vide'
    return data
Ejemplo n.º 14
0
def bookfinder(ISBN):
    global book
    global ISBN13
    #isbn = "1491953403"
    book_meta = isbnlib.meta(ISBN)
    description = isbnlib.desc(ISBN)
    print(description)
    #print(book_meta)
    title = book_meta["Title"]
    author = book_meta["Authors"][0]
    year = book_meta["Year"]
    ISBN13 = book_meta["ISBN-13"]
    app = App(title=title, layout="grid")
    Publication_Title = Text(app, text="Book Title: "+title, grid=[0,0], align="left")
    Author_Details = Text(app, text="Author(s): "+author, grid=[0,1], align="left")
    Publication_Year = Text(app, text="Year of publication: "+year, grid=[0,2], align="left")
    ISBN13Data = Text(app, text="ISBN-13: "+ISBN13, grid=[0,3], align="left")
    Description = Text(app, text="Description: "+description, grid=[0,4,1,4], align="left")
    Visit_Amazon = PushButton(app, text="Visit Amazon", command=openAmazon,grid=[0,6], align="left")
    app.display()
Ejemplo n.º 15
0
def get_isbn_from_words(query_list):
    """
    This method will the necessary metadata to a json file ( ISBN, Author and description)
    This method will return a list of ISBNs for the book titles.
    :return : list of isbns
    :rtype : list
    """
    try:
        count = 0
        failed_books = []
        successful_books_list = []
        for query in query_list:
            # 10 digit or 13 digit isbn received
            isbn = isbnlib.isbn_from_words(query)
            if isbn == None:
                print "Failed to get isbn for ", query
                continue

            # The string returned from desc() functiuon is a unicode string.hence encoding it to ascii.

            description = isbnlib.desc(isbn)
            # It is observed that for some books isbn_desc() returns None.
            # Capturing such data and continue with the next book.
            if description != None:
                description = description.encode('ascii', 'ignore')
            else:
                print "Failed to get description for isbn ", query
                failed_books.append(query)
                continue
            # "\n" is continued as a string and not interpreted as a new line.
            # Hence the following line.
            final_description = description.replace("\n", " ")

            # Same as above. Encoding it to ascii
            meta_data_dict = isbnlib.meta(isbn)
            if meta_data_dict == None:
                print "No metadata present for the book with isbn ", query
                failed_books.append(query)
                continue
            else:
                author = meta_data_dict["Authors"][0].encode('ascii', 'ignore')
            if type(author) == None:
                print "Failed to get author for isbn ", query
                failed_books.append(query)
                continue
            books_isbn_dict[query]["isbn"] = isbn
            books_isbn_dict[query]["description"] = final_description
            books_isbn_dict[query]["author"] = author
            successful_books_list.append(query)

            # Writing data to json file
            try:
                with open('book_data_base.json', 'w') as json_file_handler:
                    json.dump(dict(books_isbn_dict), json_file_handler, indent=4)
            except Exception as ex:
                print "This exception occured while printing to the json file"
                print ex
    except Exception as ex:
        print "Failed to open the file handler"
        print ex

    print len(successful_books_list)
Ejemplo n.º 16
0
from isbnlib import meta, desc, cover
from isbnlib.registry import bibformatters
import csv
import urllib.request

SERVICE = 'default'

# now you can use the service
# isbn = input('isbn')
isbn = '9781408855652'
print((meta(isbn, SERVICE)))
# my_dict = (meta(isbn,SERVICE))

print(desc(isbn))
print(cover(isbn))
# if (desc(isbn)) is None:
# 	print('desc not available')
# else:
# 	my_dict['desc'] = (desc(isbn))

# my_dict['covers'] = (cover(isbn))
# if my_dict['covers']['thumbnail'] == 'None':
# 	my_dict['covers']['thumbnail'] = 'not valid'
# print(link_url)
# data = urllib.request.urlretrieve(link_url,'test.jpg')
# print(data)
# for k,v in my_dict.items():
# print('{0}:{1}\n'.format(k,v))

# print(dict1['Title'])
# for k, v in dict1.items():
Ejemplo n.º 17
0
def start_scanner(db, csv, user):
    system('clear')
    print("[INFO] Starting stream...\n")
    camera = {"usePiCamera": True} if platform.system() == 'Linux' else {"src": 0}
    vs = VideoStream(**camera).start()
    time.sleep(1.0)
    last_book_found = {}

    while True:
        isbn_1, isbn_2 = get_user_books(user)
        if isbn_2:
            books_remaining = 0
        elif isbn_1:
            books_remaining = 1
        else:
            books_remaining = 2

        frame = vs.read()
        height, width = frame.shape[:2]
        new_height = int(video_width / width * height)
        frame = cv2.resize(frame, (video_width, new_height), interpolation=cv2.INTER_CUBIC)

        barcodes = pyzbar.decode(frame)

        for barcode in barcodes:
            isbn = barcode.data.decode("utf-8")

            if isbnlib.notisbn(isbn):
                continue

            qr_code = barcode.type == 'QRCODE'

            (x, y, w, h) = barcode.rect
            if int(w) < 100 or int(h) < 40:
                continue

            cv2.rectangle(frame, (x, y), (x + w, y + h), red, 2)

            found_book = csv.add_book(isbn, qr_code, db.add_book)

            if found_book:
                cv2.putText(frame, found_book['display_name'], (x, y - 20),
                            cv2.FONT_HERSHEY_SIMPLEX, 0.6, red, 2)
                isbn = found_book['isbn']

                if isbn != last_book_found.get('isbn'):
                    last_book_found = found_book

                    message = "Title: {}\n\nAuthors: {}\n\n".format(found_book['title'], found_book['authors'])

                    year = found_book['year']
                    publisher = found_book['publisher']

                    if year:
                        message += 'Year: {}\n\n'.format(year)

                    if publisher:
                        message += 'Publisher: {}\n\n'.format(publisher)

                    try:
                        desc = isbnlib.desc(isbn)
                        if desc:
                            message += 'Description: {}\n\n'.format(desc)
                    except Exception:
                        pass
                    system('clear')
                    print(message)

        # Display user's email on video
        cv2.putText(frame, user[0], (10, 30),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, red, 2)

        # Display checked out quantity on video
        cv2.putText(frame, 'Books Remaining: {}'.format(books_remaining), (10, 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.6, red, 2)

        title = last_book_found.get('title')
        if title:
            isbn = last_book_found['isbn']
            message = 'Press "Y" to check out this book.'

            if isbn in [isbn_1, isbn_2]:
                message = 'Press "R" to return this book.'
            elif isbn_2:
                message = 'You must return a book before checking out a new one.'

            cv2.putText(frame, message, (10, new_height - 15),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.6, red, 2)

            cv2.putText(frame, "Selected: {}".format(title), (10, new_height - 40),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.75, red, 2)

        cv2.imshow("Barcode Scanner", frame)
        key = cv2.waitKey(1) & 0xFF

        if key in [ord("q"), ord("Q")]:
            break

        if last_book_found.get('title'):
            if key in [ord("Y"), ord("y")]:
                isbn = last_book_found['isbn']
                ok, error = can_checkout(isbn, user)
                if ok:
                    updated_user, error = db.checkout_book(user[0], isbn)

                    if updated_user:
                        user = updated_user
                        print("Successfully checked out {}!\n".format(last_book_found['title']))
                    else:
                        print('[ERROR] Something went wrong', error)
                else:
                    print('[ERROR] ', error)

                last_book_found = {}


            if key in [ord("R"), ord("r")]:
                isbn = last_book_found['isbn']
                if isbn in [isbn_1, isbn_2]:
                    updated_user, error = db.return_book(user[0], isbn)

                    if updated_user:
                        user = updated_user
                        print("Successfully returned {}!\n".format(last_book_found['title']))
                    else:
                        print('[ERROR] ', error)
                else:
                    print('[ERROR] This book is not checked out to you.\n\nIf you would like to check it out, please scan it again and then press "Y"')

                last_book_found = {}

    print("[INFO] Closing stream...")
    cv2.destroyAllWindows()
    cv2.waitKey(1)
    vs.stop()
Ejemplo n.º 18
0
 def __init__(self, isbn, name):
     self.name = name
     self.cover = isbnlib.cover(isbn)['thumbnail']
     self.description = isbnlib.desc(isbn)
     self.description = self.description.replace('\n', '<br>')
     self.description = Markup(self.description)
Ejemplo n.º 19
0
def amazon(url):
    ua = UserAgent()
    headers = {'User-Agent': ua.random}
    page = requests.get(url, headers=headers)
    while True:
        sleep(3)
        try:
            parser_page = html.fromstring(page.content)
            raw_title = parser_page.xpath('//span[@id="productTitle"]//text()')
            raw_price = parser_page.xpath(
                '//span[@class="a-size-medium a-color-price offer-price a-text-normal"]'
                '//text()')
            raw_sale = parser_page.xpath(
                '//span[@class="a-size-base a-color-secondary"]//text()')
            raw_author = parser_page.xpath(
                '//a[@class="a-link-normal contributorNameID"]//text()')
            raw_category = parser_page.xpath(
                '//a[@class="a-link-normal a-color-tertiary"]//text()')
            raw_availability = parser_page.xpath(
                '//div[@id="availability"]//text()')
            ratings = parser_page.xpath('//table[@id="histogramTable"]//tr')
            reviews = parser_page.xpath(
                '//div[contains(@id,"reviews-summary")]')

            title = ''.join(''.join(raw_title).strip()) if raw_title else None
            sale = ''.join(
                ''.join(raw_sale).split()).strip() if raw_sale else None
            category = ' > '.join([i.strip() for i in raw_category
                                   ]) if raw_category else None
            price = ''.join(raw_price).strip() if raw_price else None
            availability = ''.join(
                raw_availability).strip() if raw_availability else None
            review_author = ''.join(raw_author).strip() if raw_author else None

            title_to_isbn = str(title)
            isbn = isbnlib.isbn_from_words(title_to_isbn)
            desc = str(isbnlib.desc(isbn))
            description = ''.join(desc).strip() if desc else None
            isbn10 = isbnlib.to_isbn10(isbn)
            raw_isbn13 = isbn[:3] + '-' + isbn[3:]
            isbn_13 = ''.join(raw_isbn13).strip() if raw_isbn13 else None
            isbn_10 = ''.join(isbn10).strip() if isbn10 else None

            if not reviews:
                reviews = parser_page.xpath('//div[@data-hook="review"]')

            # Rating
            ratings_dict = {}
            for ratings in ratings:
                extracted_rating = ratings.xpath('./td//a//text()')
                if extracted_rating:
                    rating_key = extracted_rating[0]
                    raw_rating_value = extracted_rating[1]
                    rating_value = raw_rating_value
                    if rating_key:
                        ratings_dict.update({rating_key: rating_value})

            # Reviews
            reviews_list = []
            for review in reviews:
                raw_review_header = review.xpath(
                    './/a[@data-hook="review-title"]//text()')
                raw_review_author = review.xpath(
                    './/a[contains(@href,"/profile/")]/parent::span//text()')
                raw_review_rating = review.xpath(
                    './/i[@data-hook="review-star-rating"]//text()')
                raw_review_posted_date = review.xpath(
                    './/a[contains(@href,"/profile/")]'
                    '/parent::span/following-sibling::span/text()')
                raw_review_text1 = review.xpath(
                    './/div[@data-hook="review-collapsed"]//text()')
                raw_review_text2 = review.xpath(
                    './/div//span[@data-action="columnbalancing-showfullreview"]'
                    '/@data-columnbalancing-showfullreview')
                raw_review_text3 = review.xpath(
                    './/div[contains(@id,"dpReviews")]/div/text()')

                review_header = ' '.join(' '.join(raw_review_header).split())
                review_author = ''.join(
                    ''.join(raw_review_author).split()).strip('By')
                review_rating = ''.join(raw_review_rating).replace(
                    'out of 5 stars', '')
                review_posted_date = dateparser.parse(
                    ''.join(raw_review_posted_date)).strftime('%d %b %Y')
                review_text = ' '.join(' '.join(raw_review_text1).split())

                if raw_review_text2:
                    json_loaded_review_data = json.loads(raw_review_text2[0])
                    json_loaded_review_data_text = json_loaded_review_data[
                        'rest']
                    cleaned_json_loaded_review_data_text = re.sub(
                        '<.*?>', '', json_loaded_review_data_text)
                    full_review_text = review_text + cleaned_json_loaded_review_data_text
                else:
                    full_review_text = review_text
                if not raw_review_text1:
                    full_review_text = ' '.join(
                        ' '.join(raw_review_text3).split())

                review_dict = {
                    'review_header': review_header,
                    'review_author': review_author,
                    'review_rating': review_rating,
                    'review_posted_date': review_posted_date,
                    'review_text': full_review_text,
                }
                reviews_list.append(review_dict)

            if not price:
                price = sale

            if page.status_code != 200:
                raise ValueError('captha')

            data = {
                'URL': url,
                'TITLE': title,
                'AUTHOR': review_author,
                'PRICE': price,
                'SALE': sale,
                'CATEGORY': category,
                'DESCRIPTION': description,
                'ISBN-10': isbn_10,
                'ISBN-13': isbn_13,
                'AVAILABILITY': availability,
                'RATING': ratings_dict,
                'REVIEW': reviews_list,
            }

            return data
        except Exception as e:
            print(e)
            if e == 'NoneType':
                return None
Ejemplo n.º 20
0
 def __init__(self, isbn):
     self.data_book = meta(isbn)
     self.data_book['Desc'] = desc(isbn)
     self.data_book['Images'] = cover(isbn)
def com_isbn_description(isbn_string):
    """
    Returns a small description of the book. Almost all data available are for US books!
    """
    return isbnlib.desc(isbn_string)
Ejemplo n.º 22
0
from isbnlib import cover
from isbnlib import desc
from pprint import pprint
from random import randint


with open('booktitles.json') as f:
    books = json.load(f)

books = books['books']
results = []

for book in books:
    isbn = isbn_from_words(book['author'] + " " + book['title'])
    print("for ", book['title'], " the isbn is ", isbn)
    try:
        metadata = meta(isbn, service='default', cache=None)
    except:
        metadata = {}

    images = cover(isbn)
    description = desc(isbn)
    book['isbn'] = isbn
    book['metadata'] = metadata
    book['desc'] = description
    book['cover'] = images
    results.append(book)
    with open('cleanbooks.json', 'w') as outfile:
        json.dump(results, outfile)

    time.sleep(randint(10,60))
Ejemplo n.º 23
0
    for row in book_dicts:
        book = (dict(row))

        #write the other necessary fields for TW5
        book['created'] = book['date_added'].replace("/", "") + ("000000000")
        book['modified'] = current_time.strftime(fmt) + "00001"

        #error handling on getting book description
        try:
            book['book_desc'] = isbn_from_words(book['isbn'])
        except:
            print("There appears to have been an error.")
            print(f"Attempting to get isbn from title: {book['title']}")
            try:
                possible_book_isbn = isbn_from_words(book['title'])
                book['book_desc'] = desc(possible_book_isbn)
            except:
                print("That didn't work either...")
                is_correct_book = "no"
                while is_correct_book != "Y":
                    possible_book_isbn = isbn_from_words(
                        input("Type book title: "))
                    isbnlib_book = meta(possible_book_isbn, SERVICE)
                    print(isbnlib_book["Title"])
                    is_correct_book = input(
                        "Is this the correct book? y/n: ").upper()

        book['type'] = "text/vnd.tiddlywiki"
        book[
            'book_image'] = "[img[http://covers.openlibrary.org/b/isbn/" + book[
                'isbn'] + "-L.jpg]]"
Ejemplo n.º 24
0
def getDesc(isbn):
    desc = isbnlib.desc(isbn)
    return desc
Ejemplo n.º 25
0
def update_catalog():
    file = 'updatedlibrarycatalog.csv'
    catalog = pd.read_csv(file)
    regFormat = bibformatters['default']
    provider = 'loc'
    prevMillis = int(round(time.time() * 1000))

    print(catalog.shape)
    print()

    n = 0
    t = 0
    f = 0

    for isbnNumber in catalog['ISBN']:
        try:
            finalISBN = str(int(isbnNumber))
            cleanISBN = isbn.clean(finalISBN)
            FINAL_ISBN = cleanISBN
            try:
                try:
                    isbnInfo = meta(cleanISBN, service=provider)
                    regFormat(isbnInfo)
                except:
                    print('Library of Congress Service Does Not Work')
                    try:
                        provider = 'goob'
                        isbnInfo = meta(cleanISBN, service=provider)
                        regFormat(isbnInfo)
                    except:
                        print('Google Service Does Not Work')
                        try:
                            provider = 'openl'
                            isbnInfo = meta(cleanISBN, service=provider)
                            regFormat(isbnInfo)
                        except:
                            print('OpenL Service Does Not Work')
                            raise ValueError()
            except:
                print("ISBN13 Num Does Not Work")
                tempValue = catalog.loc[catalog['ISBN'] ==
                                        isbnNumber]['ISBN_10'].values
                isbn10Num = tempValue[0]
                finalISBN10 = str(int(float(isbn10Num)))
                cleanISBN10 = isbn.clean(finalISBN10)
                FINAL_ISBN = cleanISBN10
                try:
                    provider = 'loc'
                    isbnInfo = meta(cleanISBN10, service=provider)
                    regFormat(isbnInfo)
                except:
                    print('Library of Congress Service Does Not Work')
                    try:
                        provider = 'goob'
                        isbnInfo = meta(cleanISBN10, service=provider)
                        regFormat(isbnInfo)
                    except:
                        print('Google Service Does Not Work')
                        try:
                            isbnInfo = meta(cleanISBN10, service='openl')
                            regFormat(isbnInfo)
                        except:
                            print('OpenL Service Does Not Work')
                            websiteURL = "https://isbnsearch.org/search?s=" + cleanISBN
                            website = urllib.request.urlopen(websiteURL)
                            mybytes = website.read()
                            dataFromWebsite = mybytes.decode("utf8")
                            website.close()
                            print(dataFromWebsite)
                            raise ValueError()

            print(regFormat(isbnInfo))

            n = n + 1

            catalog.loc[t, 'ISBN'] = isbnNumber

            bookTitle = isbnInfo['Title']
            catalog.loc[t, 'Title'] = bookTitle

            bookLanguage = isbnInfo['Language']
            catalog.loc[t, 'Language'] = bookLanguage

            bookPublisher = isbnInfo['Publisher']
            catalog.loc[t, 'Publisher'] = bookPublisher

            bookYear = isbnInfo['Year']
            catalog.loc[t, 'Year'] = bookYear

            bookAuthor = isbnInfo['Authors'][0]
            catalog.loc[t, 'Authors'] = bookAuthor

            try:
                bookDesc = isbn.desc(FINAL_ISBN)
                catalog.loc[t, 'Description'] = bookDesc
            except:
                print('Could not extract book description')

            try:
                bookCover = isbn.cover(FINAL_ISBN)
                catalog.loc[t, 'Cover'] = bookCover['thumbnail']
            except:
                print('Could not extract book cover link')

        except:
            print("This ISBN Number is NOT Valid")
            f = f + 1
        t = t + 1
        currentMillis = int(round(time.time() * 1000))
        if currentMillis - prevMillis >= 60000:
            print("Saving File to Local and Remove Server")
            catalog.to_csv('updatedlibrarycatalog.csv')
            ftp.push_file_to_server()
            prevMillis = int(round(time.time() * 1000))
            print("File has Successfully Saved")
        print("\n")

    print('Total Number of Books: ' + str(t))
    print('Successful Books: ' + str(n))
    print('Unsuccessful Books: ' + str(f))
Ejemplo n.º 26
0
def info_isbn():
    isbn = request.vars.isbn
    data = isbnlib.meta(isbn, service='merge')
    cover = isbnlib.cover(isbn)
    desc = isbnlib.desc(isbn)
    return response.json(dict(cover=cover, meta=data, desc=desc))
Ejemplo n.º 27
0
def info_isbn():
    isbn = request.vars.isbn
    data = isbnlib.meta(isbn, service='merge')
    cover = isbnlib.cover(isbn)
    desc = isbnlib.desc(isbn)
    return response.json(dict(cover=cover, meta=data, desc=desc))