예제 #1
0
def consulta(lista_isbns, servico):
    formatador_json = bibformatters['json']
    isbn_dict = {}

    if servico == 'gbooks':
        for isbn in lista_isbns:
            try:
                data = isbnlib.meta(isbn, service='goob')
                isbn_dict[str(isbn)] = formatador_json(data)
            except isbnlib.dev.DataNotFoundAtServiceError:
                print("Entrada com ISBN %s não foi encontrada no serviço %s." % (isbn, servico))    
            except isbnlib.dev._exceptions.NoDataForSelectorError:
                print("Entrada com ISBN %s não foi encontrada no serviço %s." % (isbn, servico))    
    elif servico == 'openl':
        for isbn in lista_isbns:
            try:
                a = isbn
                a = a.strip()
                data = isbnlib.meta(isbn, service = 'openl')
                isbn_dict[str(isbn)] = formatador_json(data)
            except isbnlib.dev.DataNotFoundAtServiceError:                    
                print("Entrada com ISBN %s não foi encontrada no serviço %s." % (isbn, servico))
    elif servico == 'crref':
        for isbn in lista_isbns:
            a = isbn
            a = a.strip()
            works = Works()
            l = works.filter(isbn = str(a))
            b = []
            for item in l:
                b.append((item))
예제 #2
0
def search_add(isbn):
    db = sqlite3.connect('test.db')
    db.row_factory = sqlite3.Row
    cursor = db.cursor()

    if isbnlib.is_isbn13(isbn):
        info = isbnlib.meta(isbn)
        au = ", ".join(info['Authors'])
        addBook(cursor, info['ISBN-13'], info['Title'], au, info['Year'],
                info['Publisher'], getCoverSmall(isbn), getCover(isbn),
                getDesc(isbn))

        db.commit()
        return search_equals(cursor, 'ISBN', isbn)
    elif isbnlib.is_isbn10(isbn):
        isbn = isbnlib.to_isbn13(isbn)
        info = isbnlib.meta(isbn)
        au = ", ".join(info['Authors'])
        addBook(cursor, info['ISBN-13'], info['Title'], au, info['Year'],
                info['Publisher'], getCoverSmall(isbn), getCover(isbn),
                getDesc(isbn))

        db.commit()
        return search_equals(cursor, 'ISBN', isbn)
    else:
        print("Not a valid ISBN")
        return None

    db.commit()
    db.close()
예제 #3
0
def test_isbn_extraction():
    """
    For further usage, not used at the moment
    """

    isbn = isbnlib.isbn_from_words("to kill a mockingbird")
    # isbn = '3493589182'

    print isbnlib.meta(isbn, service='default', cache='default')
예제 #4
0
def get_isbn_metadata(isbn):
    # Takes the ISBN and appends information from it into a list
    # isbn.meta() gives the metadata of the ISBN in a dictionary format

    '''
    try:
        isbnMeta = isbnlib.meta(str(isbn), service='wiki') # Grabs metadata of ISBN

        return isbnMeta  # Returns dict of the ISBN meta data

    except isbnlib.ISBNLibException:
        # Try different service (Google Books) for searching the ISBN information
        isbnMeta = isbnlib.meta(str(isbn), service='goob')

        return isbnMeta
    '''
    isbnMetaList = []

    try:
        isbnMeta = isbnlib.meta(str(isbn), service='wiki')
        if bool(isbnMeta):  # Check to make sure it does not return an empty dictionary
            isbnMetaList.append(isbnMeta)
    except:
        pass
    try:
        isbnMeta = isbnlib.meta(str(isbn), service='goob')
        if bool(isbnMeta):
            isbnMetaList.append(isbnMeta)
    except:
        pass
    try:
        isbnMeta = isbnlib.meta(str(isbn), service='openl')
        if bool(isbnMeta):
            isbnMetaList.append(isbnMeta)
    except:
        pass

    layout = [
        [sg.Text("Results From Searching Wiki Books, Google Books, and OpenLibrary")],
        [sg.Text("The selection from this page will input the data for the book")],
        [sg.Listbox(values=isbnMetaList, size=(200, 6), key='-BOOK-', bind_return_key=True)],
        [sg.Button('Submit'), sg.Button('Cancel')]
    ]

    isbnMetaWindow = sg.Window('Select the Book', layout=layout)
    while True:
        eventISBNMeta, valuesISBNMeta = isbnMetaWindow.Read()
        if eventISBNMeta == sg.WIN_CLOSED or eventISBNMeta == 'Cancel':
            book = 'cancel'
            isbnMetaWindow.Close()
            return book
        if eventISBNMeta == 'Submit':
            if valuesISBNMeta['-BOOK-']:
                book = valuesISBNMeta['-BOOK-']
                isbnMetaWindow.Close()
                return book
예제 #5
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
예제 #6
0
def getisbninfo(isbninput):
    # make sure its an isbn thats inputted
    if isibnvalid(isbninput):
        # meta actually queries the database and outputs a dictionary containing authors and other info
        try:
            foundbook = isbnlib.meta(isbninput)
        except:
            tryanyways = input(
                "ISBN could not be found. Search libgen anyways? Y/N: ").upper(
                )
            if (tryanyways == "Y"):
                searchlibgen(isbninput)
                return
            else:
                return
        print("ISBN: " + isbninput)
        print("Title: " + foundbook['Title'] + "\n")
        # make new line not just for clean format but also cause we cant concatenate list + string
        print("Author(s): ")
        # separate each part of the dict. into separate lines
        print("\n".join(foundbook['Authors']))
        # open coverimage in browser so user can verify its the right book
        showcover = input("Show cover? Y/N: ").upper()
        if showcover == "Y":
            coverimage = isbnlib.cover(isbninput)
            # print(coverimage)
            webbrowser.open(coverimage["thumbnail"])
        searchlibgen(isbninput)
    else:
        lasttry = input(
            "ISBN is invalid- search libgen anyways? Y/N: ").upper()
        if (lasttry == "Y"):
            searchlibgen(isbninput)
예제 #7
0
def sell_isbn_search(request):
    if request.method == "POST":
        input_isbn = request.POST.get("book_isbn", None)
        if len(input_isbn) < 10 or len(input_isbn) == 11 or len(input_isbn) == 12 or len(input_isbn) > 13:
            input_isbn = ""
        if input_isbn is None:
            input_isbn = ""
        if len(input_isbn) != 0:
            try:
                book = isbnlib.meta(input_isbn)
                book_details = []
                context = {}
                if book is not None:
                    if book['Title'] is not None:
                        context = book
                        context['isbn'] = input_isbn
                        return render(request, 'sell_input.html', context)
                    else:
                        return render(request, 'sell_input.html')
                else:
                    return render(request, 'sell_input.html')
            except:
                return render(request, 'sell_input.html')
        else:
            return render(request, 'sell_input.html')
    else:
        return render(request, 'sell.html')
예제 #8
0
 def get_meta(self):
     """
     Return the book's meta data (Title, Authors, Year, etc...) in a dictionary form, with the isbn13 field masked.
     """
     d = meta(canonical(self.isbnlike))
     d['ISBN-13'] = mask(d['ISBN-13'])
     return d
예제 #9
0
def get_cover(isbn):
    book = meta(isbn)
    data = isbnlib.cover(isbn)
    try:
        return data['thumbnail']
    except:
        return 'http://tri-solution.com/addons/7G20/themes/firesale_mediatheme/images/no-image.png'
예제 #10
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
예제 #11
0
def _fix_based_on_isbn(isbn_string, entry):
    """Try to find publlisher and year based ISBN."""
    publisher = None
    year = None
    if 'publisher' in entry and entry['publisher'] != 'TODO':
        publisher = entry['publisher']
    if 'year' in entry and entry['year'] != 'TODO':
        year = entry['year']

    try:
        if not publisher or not year:
            meta_data = isbnlib.meta(isbn_string)

            if 'Year' in meta_data and entry['year'] == 'TODO':
                entry['year'] = meta_data['Year']
                log_message(
                    entry,
                    "year found based on ISBN: {}".format(meta_data['Year']))
            if 'Publisher' in meta_data and entry['publisher'] == 'TODO':
                entry['publisher'] = meta_data['Publisher']
                log_message(
                    entry, "publisher found based on ISBN: '{}'".format(
                        meta_data['Publisher']))
    # pylint: disable=bare-except
    except:
        pass
예제 #12
0
def test(isbnx):
    book = isbnlib.meta(isbnx)
    data = isbnlib.cover(isbnx)
    try:
        return data['thumbnail']
    except:
        print("Handled error ")
예제 #13
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")
예제 #14
0
def CreateBookByISBN():
    try:
        i = 0
        for isbn in saved_column.values.tolist():
            if type(isbn) is str:
                book = isbnlib.meta(isbn)
                listOfBookDicts.append(book)

        for d in listOfBookDicts:  # you can list as many input dicts as you want here
            if d is not None:
                for key, value in d.items():
                    dd[key].append(value)

        for k, v in dd.items():
            for each in v:
                if (len(each) > 1) and type(each) == list:
                    dd[k].remove(each)
                    dd[k].insert(i, ';'.join(each))
                    i = i + 1
                elif type(each) == list:
                    dd[k].remove(each)
                    dd[k].insert(i, ''.join(each))
                    i = i + 1

        createOrderDict(dd, librarikaData)

        createExcelSheet(finalFeatureDict)
        Excel2CSV("BookListExcelColumn.xlsx", "Sheet1")
    except Exception as ex:
        print(ex)
        pass
예제 #15
0
def download_isbn():
    with open('raw.json') as input:
        data = json.load(input)
    '''
    print("Loading index")
    md = readmetadata()
    for record in data:
        id = record['metadata']['id']
        metadata = md[id]
        pprint(metadata)
        sys.exit(0)
        title = record['book']['title']
        isbn = isbnlib.isbn_from_words(title)
        metadata = isbnlib.meta(isbn)
        pprint(metadata)
        extracted_title = ''
        print title, extracted_title, isbn
        time.sleep(1)'''
    url = 'http://www.librarything.com/api/thingTitle/'
    for record in data:
        title = record['book']['title']
        final_url = url+quote_plus(title)
        content = requests.get(final_url).content
        soup = BeautifulSoup(content)
        extracted_title = soup.idlist.title.string
        isbn = soup.idlist.find("isbn").string
        metadata = isbnlib.meta(isbn)
        pprint(metadata)
        #print title, extracted_title, min(isbns)
        time.sleep(1)
예제 #16
0
    def post(self):
        # Required arguments
        self.reqparse.add_argument("title",
                                   type=str,
                                   required=True,
                                   location='json')

        args = self.reqparse.parse_args()

        user = g.user
        if not user:  # User not found
            return {'message': 'User not found'}, log__(404, g.user)
        try:
            isbn = isbn_from_words(args['title'])
            title = meta(isbn)['Title']

            wish = Wishlist.query.filter_by(isbn=isbn, user_id=user.id).first()

            if wish:  # Book already in the wishlist
                return {'data': wish.serialize}, log__(200, g.user)
            else:  # If book not in the wishlist
                new_wish = Wishlist(isbn=isbn, title=title, user_id=user.id)
                db.session.add(new_wish)
                db.session.commit()
                return {'data': new_wish.serialize}, log__(201, g.user)
        except Exception as error:
            print(error)
            return {'message': 'Unexpected Error'}, log__(500, g.user)
예제 #17
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
예제 #18
0
    def form_valid(self, form):
        self.publication = form.save(commit=False)
        self.publication.created_by = self.request.user
        works = Works()
        if self.publication.DOI != "" and works.doi_exists(self.publication.DOI):
            paper_data_result = works.doi(self.publication.DOI)
            self.publication.publication_year = str(paper_data_result.get('created').get('date-parts')[0][0])
            self.publication.title = paper_data_result.get('title')[0]
            self.publication.author = f"{paper_data_result.get('author')[0].get('given')},{paper_data_result.get('author')[0].get('family')}"
            sub = paper_data_result.get("subject", [self.publication.subject])
            self.publication.subject = ', '.join([str(elem) for elem in sub])
            self.publication.URL = paper_data_result.get('URL')

        elif self.publication.ISBN != "" and is_isbn13(self.publication.ISBN):
            book_data_result = meta(self.publication.ISBN)
            self.publication.publication_year = book_data_result.get('Year')
            self.publication.title = book_data_result.get('Title')
            self.publication.author = book_data_result.get('Authors')[0]

        elif self.publication.crossref and (self.publication.DOI or self.publication.ISBN):
            messages.error(self.request, 'DOI/ISBN no encontrado. Cargar datos y desmarcar el campo "tiene DOI/ISBN"')
            return render(self.request, 'bibliography/publication_form.html', {'form': form})
        self.publication.save()
        messages.success(self.request, "Registro realizado con exito")

        return redirect('bibliography:publication_detail', pk=self.publication.pk)
예제 #19
0
def get_isbn_metadata(isbn):
    try:
        rv = isbnlib.meta(isbn)
        if rv:
            return _format_isbnlib(rv)
    except isbnlib.NotValidISBNError:
        return None
예제 #20
0
    def call_isbnlin_meta(self, isbn):

        meta = {}
        logger.debug('Searching ' + isbn + ' on ' + self.isbndb)
        count = 0
        while count <= self.MAX_HTTP_RETRY:
            try:
                meta = isbnlib.meta(isbn,  self.isbndb)
            except Exception as ex:
                if ex.message.startswith('an HTTP error has ocurred'):
                    logger.debug('HTTP error ... ...')
                    logger.debug('Sleep Start : %s' % time.ctime())
                    count += 1
                    time.sleep(self.LONG_SLEEP * count)
                    logger.debug('Sleep End : %s' % time.ctime())
                    logger.debug('End of Try ' + str(count))
                elif ex.message.startswith('an URL error has ocurred'):
                    logger.debug('URL error ... ...')
                    count += 1
                else:
                    logger.debug('Exception: ' + ex.message)
                    logger.debug('Metadata of ISBN ' + isbn + ' Not Found')
                    logger.debug('')
                    if self.status != self.STATUS_HTTPERROR:
                        self.status = self.STATUS_NOTFOUND
                    break
            else:
                self.print_metadata(meta)
                break
        if count > self.MAX_HTTP_RETRY:
            self.status = self.STATUS_HTTPERROR
        return meta
예제 #21
0
def set_ebook_metadata():
    print "::: PDF Metadata running... "
    # directory_name = get_directory_name()
    directory_name = "/Users/htenjo/eBooks/"
    files = list_files(directory_name)

    for file_name in files:
        try:
            print "::: Processing file %s ..." % file_name
            isbn = get_isbn_from_file(file_name)
            print "ISBN OK"
            metadata = isbnlib.meta(isbn)
            print "METADATA OK"

            if metadata is None:
                os.rename(file_name, get_new_file_name_from_old_path(file_name));
                continue

            metadata = clean_metatada(metadata)
            print metadata
            print "METADATA CLEANED"

            if metadata.has_key(TITLE_META_NAME) and \
                    metadata.has_key(AUTHOR_META_NAME) and metadata.has_key(ISBN_META_NAME):
                add_metadata(file_name, metadata, directory_name)
            else:
                os.rename(file_name, get_new_file_name_from_old_path(file_name))
        except Exception as err:
            os.rename(file_name, get_new_file_name_from_old_path(file_name))
            print "ERROR: File with errors ", file_name, err.__str__()
def bookdata(df):
    year = []
    pbar = ProgressBar()
    for isbn in pbar(df.isbn13):
        try:
            details = isbnlib.meta(isbn)
            year.append(details['Year'])
        except:
            try:
                book_detail = client.Book.show_by_isbn(isbn)
                keys_wanted = ['publication_year']
                reduced_book = {
                    k: v
                    for k, v in book_detail.items() if k in keys_wanted
                }
                year.append((reduced_book['publication_year']))

            except:
                try:
                    y = html(isbn)
                    year_extracted = reg(y)
                    year.append(y)
                except:
                    year.append('0')

    return year
예제 #23
0
def get_unmodified_isbn_data(query):
    import isbnlib
    isbn = isbnlib.isbn_from_words(query)
    data = isbnlib.meta(isbn, service="openl")
    assert data is not None

    return data
    def isbnlookup(self):
        isbn = self.lineEdit.text()
        try:
            bookisbn = isbnlib.meta(str(isbn))
            # title = bookisbn['Title']
            if len(bookisbn) > 0:
                title = bookisbn['Title']
                authors = bookisbn['Authors']
                authors = " ".join(authors)

                self.lineEdit_2.setText(title)
                self.lineEdit_4.setText(authors)
                #self.object.addbook(title, authors,isbn)
                self.lineEdit_2.repaint()
                self.lineEdit_4.repaint()

            else:
                msg = QMessageBox()
                msg.setWindowTitle("Library")
                msg.setText("ERROR: Invalid ISBN")
                x = msg.exec_()
        except isbnlib._exceptions.NotValidISBNError:
            msg = QMessageBox()
            msg.setWindowTitle("Library")
            msg.setText("ERROR: Invalid ISBN")
            x = msg.exec_()
예제 #25
0
 async def search_book_2(self, isbn: str, keywords: str) -> dict:
     if isbn is None:
         if keywords is None:
             raise ValueError
         info = self.cache.get(keywords, None)
         if info is not None:
             return info
         isbn = isbnlib.isbn_from_words(keywords)
     info = dict()
     for key in ['wiki', 'default', 'openl', 'goob']:
         try:
             i = isbnlib.meta(isbn, service=key)
         except (isbnlib.dev._exceptions.DataNotFoundAtServiceError,
                 isbnlib.dev._exceptions.ISBNLibHTTPError):
             continue
         if i is not None and len(i) > 0:
             info.update({'title': i['Title'], 'authors': i['Authors']})
             if i['Year']:
                 info['publication'] = i['Year']
             if i['Publisher']:
                 info['publisher'] = i['Publisher']
             if 'language' not in info and len(i['Language']) > 0:
                 info['language'] = i['Language']
     if len(info) > 0:
         co = isbnlib.cover(isbn)
         if 'thumbnail' in co:
             info['cover'] = co['thumbnail']
         info['isbn'] = isbn
     info = None if len(info) == 0 else info
     self.cache[keywords] = info
     return info
예제 #26
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})
예제 #27
0
def raamat_ribakoodist(failinimi):
    import cv2
    import isbnlib
    from pyzbar.pyzbar import decode
    isbn = decode(cv2.imread(failinimi))[0].data.decode('ascii')
    meta = isbnlib.meta(isbn)
    return {'Autor': meta['Authors'][0], 'Pealkiri': meta['Title']}
예제 #28
0
    def update_metadata(self):

        try:
            data = isbnlib.meta(str(self.isbn), 'wcat')

            self.title = data.get('Title')
            self.year = data.get('Year') or 1900
            self.publisher, _ = Publisher.objects.get_or_create(name=data.get('Publisher', 'Unknow'))
            self.author.clear()

            for author in data.get('Authors', []):
                for splited_author in author.split(', '):
                    author_object, _ = Author.objects.get_or_create(name=splited_author)

                    self.author.add(author_object)
        except:

            self.title = self.title or '?'
            self.year = self.year or 1900

            try:
                truc = self.publisher
            except:
                self.publisher, _ = Publisher.objects.get_or_create(name='Unknow')

        self.save()
예제 #29
0
def download_isbn():
    with open('raw.json') as input:
        data = json.load(input)
    '''
    print("Loading index")
    md = readmetadata()
    for record in data:
        id = record['metadata']['id']
        metadata = md[id]
        pprint(metadata)
        sys.exit(0)
        title = record['book']['title']
        isbn = isbnlib.isbn_from_words(title)
        metadata = isbnlib.meta(isbn)
        pprint(metadata)
        extracted_title = ''
        print title, extracted_title, isbn
        time.sleep(1)'''
    url = 'http://www.librarything.com/api/thingTitle/'
    for record in data:
        title = record['book']['title']
        final_url = url + quote_plus(title)
        content = requests.get(final_url).content
        soup = BeautifulSoup(content)
        extracted_title = soup.idlist.title.string
        isbn = soup.idlist.find("isbn").string
        metadata = isbnlib.meta(isbn)
        pprint(metadata)
        #print title, extracted_title, min(isbns)
        time.sleep(1)
예제 #30
0
파일: __init__.py 프로젝트: puhoy/lspace
def find_meta_by_text(words):
    if isbnlib.is_isbn13:
        click.echo('%s looks like isbn!' % words)
        results = isbnlib.meta(words, service='openl')
    else:
        results = isbnlib.goom(words)
    click.echo(yaml.dump(results))
def bookdata(df):
    year = []
    pbar = ProgressBar()
    for isbn in pbar(df.isbn13):
        try:
            details = isbnlib.meta(isbn)
            year.append(details['Year'])
        except:
            #Trying out with goodreads api now
            try:
                book_detail = client.Book.show_by_isbn(isbn)
                keys_wanted = ['publication_year']
                reduced_book = {
                    k: v
                    for k, v in book_detail.items() if k in keys_wanted
                }
                year.append((reduced_book['publication_year']))

            except:
                #Going with webscraping
                try:
                    y = html(isbn)
                    year_extracted = reg(y)  #Extracting year with regex
                    year.append(y)
                except:
                    year.append('0')

    return year
예제 #32
0
def get_barcode_from_scanner(barcode):
    ISBN = get_ISBN_from_barcode(barcode)
    print(ISBN, "ISBN")
    book_info = isbnlib.meta(ISBN)
    print(book_info)
    book_cover = isbnlib.cover(ISBN)

    times_scanned = models.search_ISBN_get_times_scanned(ISBN)

    if times_scanned == None:
        models.insert_books(str(book_info['Title']), str(book_info['Authors']),
                            str(ISBN), str(book_cover['thumbnail']), 1)
        res = [
            str(book_info['Title']),
            str(book_info['Authors']),
            str(ISBN),
            str(book_cover['thumbnail']), 1
        ]
        socketio.emit('barcode', {'data': res}, namespace="/awesome")
    else:
        models.update_times_scanned(times_scanned + 1, ISBN)
        res = models.get_info_from_ISBN(ISBN)
        socketio.emit('update_data', {'data': res}, namespace="/awesome")

    return render_template('index.html', data=[])
예제 #33
0
def isbn2Bib(isbn):
    """Tries to get bibtex entry from an ISBN number"""
    # Default merges results from worldcat.org and google books
    try:
        return isbnlib.registry.bibformatters['bibtex'](isbnlib.meta(isbn,
                                                                     'default'))
    except (isbnlib.ISBNLibException, isbnlib.ISBNToolsException, TypeError):
        return ''
예제 #34
0
def isbn2Bib(isbn):
    """Tries to get bibtex entry from an ISBN number"""
    # Default merges results from worldcat.org and google books
    try:
        return isbnlib.registry.bibformatters['bibtex'](isbnlib.meta(isbn,
                                                                     'default'))
    except (isbnlib.ISBNLibException, TypeError):
        return ''
예제 #35
0
def get_isbn_csl_item_isbnlib(isbn):
    """
    Generate CSL JSON Data for an ISBN using isbnlib.
    """
    import isbnlib
    metadata = isbnlib.meta(isbn, cache=None)
    csl_json = isbnlib.registry.bibformatters['csl'](metadata)
    csl_data = json.loads(csl_json)
    return csl_data
예제 #36
0
	def __collect_metadata(self,isbn,service, canonical) :
		try :
			record = isbnlib.meta(isbn, service=service)
			if canonical :
				for key in canonical :
					if not canonical[key] and record[key]:
						canonical[key] = record[key]
			else :
				return record
		except :
			pass
		return canonical
예제 #37
0
파일: main.py 프로젝트: Sperlea/cittex
    def add_publication_from_isbn(self, isbn):
        isbnlib.config.add_apikey("isbndb", "2TCD2CVI")
        bibtex = bibformatters['bibtex']

        data = isbnlib.meta(isbn, "isbndb")
        for part in data:
            if not data[part]:
                data[part] = input("Missing Value! Please input value for the field " + part + ". ")
        data["ISBN-13"] = data["Authors"][0].split(", ")[0] + "_" + str(data["Year"])

        new_bibtex = bibtex(data).replace("  ", "").replace("\n ", "\n").split("\n")
        self.add_publication_from_bibtex(new_bibtex)
예제 #38
0
def check_isbn(request):

    isbn = clean_isbn(request.GET.get('isbn', ''))

    if not isbnlib.is_isbn13(isbn):
        return HttpResponse('<script type="text/javascript">$(\'#form-group-isbn\').attr(\'class\', \'has-warning\');</script><span class="text-warning"><i class="glyphicon glyphicon-warning-sign"></i> %s</span>' % (unicode(_('Not an ISBN')), ))

    data = isbnlib.meta(str(isbn))

    if not data or not data.get('Authors'):
        return HttpResponse('<script type="text/javascript">$(\'#form-group-isbn\').attr(\'class\', \'has-danger\');</script><span class="text-danger"><i class="glyphicon glyphicon-remove"></i> %s</span>' % (unicode(_('Cannot found this ISBN in online databases')), ))

    return HttpResponse('<script type="text/javascript">$(\'#form-group-isbn\').attr(\'class\', \'has-success\');</script><span class="text-success"><i class="glyphicon glyphicon-ok"></i> %s</span>' % (unicode(_('Good ISBN !')), ))
예제 #39
0
def get_isbn_metadata(isbn):
    """ For a given valid ISBN number (-10 or -13) return the corresponding
        metadata.

    :param isbn:    A valid ISBN-10 or ISBN-13
    :type isbn:     unicode
    :returns:       Metadata for ISBN
    :rtype:         dict or `None` if ISBN is not valid or does not exist
    """
    try:
        rv = isbnlib.meta(isbn)
        if rv:
            return _format_isbnlib(rv)
    except isbnlib.NotValidISBNError:
        return None
예제 #40
0
def get_metadata_from_valid_isbn(isbn):
    """ """
    metadata = None
    servers = ('wcat', 'goob', 'openl', 'merge')
    for server in servers:
        try:
            metadata = isbnlib.meta(isbn, server)
            if metadata is not None:
                break
        except:
            pass
    else:
        return None
    authors_string = ''
    for author in metadata['Authors']:
        authors_string += author + ' '
    return (authors_string[:-1], metadata['Title'])
예제 #41
0
파일: isbn.py 프로젝트: Armavica/libbmc
def get_bibtex(isbn_identifier):
    """
    Get a BibTeX string for the given ISBN.

    :param isbn_identifier: ISBN to fetch BibTeX entry for.
    :returns: A BibTeX string or ``None`` if could not fetch it.

    >>> get_bibtex('9783161484100')
    '@book{9783161484100,\\n     title = {Berkeley, Oakland: Albany, Emeryville, Alameda, Kensington},\\n    author = {Peekaboo Maps},\\n      isbn = {9783161484100},\\n      year = {2009},\\n publisher = {Peek A Boo Maps}\\n}'
    """
    # Try to find the BibTeX using associated DOIs
    bibtex = doi.get_bibtex(to_doi(isbn_identifier))
    if bibtex is None:
        # In some cases, there are no DOIs for a given ISBN. In this case, try
        # to fetch bibtex directly from the ISBN, using a combination of
        # Google Books and worldcat.org results.
        bibtex = isbnlib.registry.bibformatters['bibtex'](
            isbnlib.meta(isbn_identifier, 'default'))
    return bibtex
예제 #42
0
  def __init__(self, catalog):
    print('Enter ISBN to search for')
    isbn = input()
    bookResult = meta(isbn)

    print(bookResult)

    print('a) Add to catalog v) view extended information')
    choice = input()

    if choice == 'a':
        book = {}
        book['title'] = bookResult['Title'].replace(',', '')
        book['slug'] = slugify(book['title'])
        book['ID'] = catalog.get_next_id()
        book['year'] = bookResult['Year']
        book['publisher'] = bookResult['Publisher'].replace(',', '')
        book['ISBN'] = bookResult['ISBN-13']
        catalog.add_book(book)
        catalog.save()
        ListBooksScreen(catalog)
def valid():
    # create ten variables to store each number in the ISBN and multiply it by its position
    # for number validation
    firstNum = int(isbnInput[0]) * 10
    secondNum = int(isbnInput[1]) * 9
    thirdNum = int(isbnInput[2]) * 8
    fourthNum = int(isbnInput[3]) * 7
    fithNum = int(isbnInput[4]) * 6
    sixthNum = int(isbnInput[5]) * 5
    seventhNum = int(isbnInput[6]) * 4
    eigthNum = int(isbnInput[7]) * 3
    ninethNum = int(isbnInput[8]) * 2
    # sometimes, the last number in the ISBN is a Ten, which is written as an 'X'
    if isbnInput[9] == 'X':
        tenthNum = 10
    # otherwise, do the math
    else:
        tenthNum = int(isbnInput[9]) * 1

    # calculate the sum of all of the expanded numbers above and store as isbnSum
    isbnSum = firstNum + secondNum + thirdNum + fourthNum + fithNum\
              + sixthNum + seventhNum + eigthNum + ninethNum + tenthNum
    print ('The sum of the ISBN is: ' + str(isbnSum))

    # this is where we call the isbnlib method to_isbn13 which converts ISBN10 numbers
    # to ISBN13
    isbnFinal = isbnlib.to_isbn13(isbnInput)

    # this is where we check to see if the ISBN that the use entered is valid at all
    # or tell them that it's not
    if isbnSum % 11 == 0:
        print ('You entered a valid ISBN number')
        # this is where we call isbnlib's other function called meta()
        # parameters are the ISBN you wish to look up, the service you want to use to
        # look it up, and how much memory you want to allocate this information
        print (isbnlib.meta(isbnInput, service = 'merge', cache = 'default'))
    elif isbnSum % 11 != 0:
        print str(isbnFinal) + ' is not a valid ISBN number'
@require: sys, os, isbntools
@sample: python rename_Book_by_ISBN.py in.pdf 9780980232714
@note: WorldCat.org service is blocked in China mainland.
	   Maybe you should use VPN to connect to worldcat service.
	   And I recommend GreenVPN, link: http://gjsq.link
	   In addition, this is my recommendation link: http://gjsq.me/r2869780
	   And this script is not used in GUI.
"""
import sys

ISBNStr = sys.argv[2]

import isbnlib

BibContentDict = isbnlib.meta(ISBNStr, service="wcat")

FirstAuthorStr = BibContentDict['Authors'][0]
if "et al" in FirstAuthorStr:
	FirstAuthorList = FirstAuthorStr.split()
	for StrInd in range(len(FirstAuthorList)):
		if FirstAuthorList[StrInd] == "...":
			FirstAuthorLastNameStr = FirstAuthorList[StrInd-1].lower()
else:
	FirstAuthorList = FirstAuthorStr.split()
	FirstAuthorLastNameStr = FirstAuthorList[-1].lower()

YearStr = BibContentDict['Year']

TitleRawStr = BibContentDict['Title']
TitleList = TitleRawStr.split()
예제 #45
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--batchsize", "-b", type=int, default=8)
    parser.add_argument("input")
    parser.add_argument("output")
    args = parser.parse_args()
    countdown = args.batchsize
    with io.open(args.input, 'r', encoding='utf-8') as input:
        books_reader = csv.DictReader(input)
        with io.open(args.output, 'w', encoding='utf-8') as output:
            books_writer = csv.DictWriter(output, fieldnames)
            books_writer.writeheader()
            for row in books_reader:
                if countdown > 0 and not row.get('webchecked', None):
                    isbn = str(row.get('ISBN', None))
                    if len(isbn) == 9:
                        isbn = "0" + isbn
                    if isbn:
                        countdown = countdown - 1
                        new_isbn = isbnlib.to_isbn13(isbnlib.canonical(isbn))
                        if new_isbn is None or new_isbn == "":
                            print "Could not canonicalize isbn", isbn
                        else:
                            row['ISBN'] = new_isbn
                        details = None
                        try:
                            details = isbnlib.meta(isbn)
                        except isbnlib.dev._exceptions.NoDataForSelectorError:
                            print "No data for ISBN", isbn, "title", row.get('Title', "Unknown")
                            row['webchecked'] = "No data for ISBN"
                        except isbnlib._exceptions.NotValidISBNError:
                            print "Invalid ISBN", isbn, "for", row['Title']
                            row['webchecked'] = "Invalid ISBN"
                        except isbnlib.dev._exceptions.ISBNNotConsistentError:
                            print "Inconsistent data for",  row['Title']
                            row['webchecked'] = "Inconsistent ISBN data"
                        if details:
                            if details.get('ISBN-13', "") != "" and row.get('ISBN', "") == "":
                                row['ISBN'] = details['ISBN-13']
                            if 'Authors' in row:
                                row['Authors'] = row['Authors'].split('/')
                            old_title = row['Title']
                            web_title = details['Title']
                            if old_title != web_title:
                                old_canon = canonicalize_title(old_title)
                                web_canon = canonicalize_title(web_title)
                                old_len = len(old_canon)
                                web_len = len(web_canon)
                                if ((web_len > old_len and old_canon in web_canon)
                                    or (web_len == old_len and old_canon == web_canon)):
                                    print "Title improvement from", old_title, "to", web_title
                                else:
                                    print "Title discrepancy:", old_title, "in file,", web_title, "found online"
                                    details['Title'] = old_title
                            # don't use 'update', because we don't want to drag in random other fields that dictwriter will then object to
                            for key in fieldnames:
                                if key in details:
                                    row[key] = details[key]
                            if 'Authors' in row:
                                row['Authors'] = '/'.join(row['Authors'])
                            row['webchecked'] = "OK"
                # from https://docs.python.org/2/library/csv.html
                encoded_row = {k: (v.encode("utf-8") if isinstance(v, basestring) else v)
                               for k,v in row.iteritems()}
                books_writer.writerow(row)
        if match:
            FILETYPE = match.groups()[0]
#HREF = url that leads to book.json in GCIS-DEV
        HREF = 'https://gcis-search-stage.jpl.net:3000/{}/{}.json' .format(FILETYPE,IDEN)
        HREFPAR = parse(HREF)
#Extracts book title and isbn from GCIS-DEV
        d = dict(HREFPAR)
        TITLE = d['title']
        ISBNS = d['isbn']
#Cleans ISBNS to only conatian valid characters
        CISBN = clean(ISBNS)
#V13 = validated canonical ISBN-13
        V13 = EAN13(CISBN)
        if V13 is None:
            V13 = canonical(CISBN)
        M = parse(HREF)
        v = meta(V13, service = 'goob', cache ='default')
        GCISDATA = "GCIS-DEV\n\n\t{}\n\n\tisbn_original:{}\n\n\tisbn_mod:{}\n\n" .format(M, ISBNS, V13)
        APIDATA = "GOOB\n\n\t{}\n\n------------\n\n" .format(v)
        print("GCIS-DEV\n\n\t", M, '\n\n\t', "isbn_original:", ISBNS, '\n\n\t', "isbn_mod:", V13, "\n\n")
        print ("GOOB\n\t","\n\t", v, '\n')
        file2.write(GCISDATA)
        file2.write(APIDATA)


    except:
        Error = '\n\t######## PROBLEM #######\n\tTitle:{}\n\tGCIS-ISBN:{}\n\tIdentifier:{}\n\n'.format(TITLE, ISBNS, IDEN)
        print(Error)
        file.write(Error)

예제 #47
0
파일: get_isbn.py 프로젝트: Amit232/bookshq
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)
def com_isbn_meta(isbn_string):
    """
    Gives you the main metadata associated with the ISBN. As service parameter you can use: 'goob' uses the Google Books service (no key is needed) and is the default option, 'openl' uses the OpenLibrary.org api (no key is needed). You can enter API keys with config.add_apikey(service, apikey) (see example below). The output can be formatted as bibtex, csl (CSL-JSON), msword, endnote, refworks, opf or json (BibJSON) bibliographic formats with isbnlib.registry.bibformatters. cache only allows two values: 'default' or None. You can change the kind of cache by using isbnlib.registry.set_cache (see below). Now, you can extend the functionality of this function by adding pluggins, more metadata providers or new bibliographic formatters (check for available pluggins).
    """
    return isbnlib.meta(isbn_string, service='default', cache='default')
예제 #49
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))
예제 #50
0
from jinja2 import Environment, FileSystemLoader

parser = argparse.ArgumentParser()
parser.add_argument('isbnfile', type=file,
                    help='file to load ISBNs from',
                    nargs='?')
parser.add_argument('-t', '--template',
                    help='Choose template to use',
                    default='shelf.j2')
parser.add_argument('-s', '--service',
                    help='Choose service to use',
                    choices=['merge', 'wcat', 'goob', 'openl'],
                    default='openl')
args = parser.parse_args()

print args

env = Environment(loader=FileSystemLoader('.'), trim_blocks=True)
template = env.get_template(args.template)

booklist = []

if args.isbnfile is not None:
    for line in args.isbnfile:
        booklist.append(isbnlib.meta(line, args.service))
else:
    for line in sys.stdin:
        booklist.append(isbnlib.meta(line, args.service))

print template.render(books=booklist),
        try:
            HREF = 'https://gcis-search-stage.jpl.net:3000/{}/{}.json' .format(FILETYPE,IDEN)
            #HREF = 'https://gcis-search-stage.jpl.net:3000/book/13b8b4fc-3de1-4bd8-82aa-7d3a6aa54ad5.json'
            HREFPAR = parse(HREF)
    #Extracts book title and isbn from GCIS-DEV
            d = dict(HREFPAR)
            TITLE = d['title']
            ISBNS = d['isbn']
    #Cleans ISBNS to only conatian valid characters
            CISBN = clean(ISBNS)
    #V13 = validated canonical ISBN-13
            V13 = EAN13(CISBN)
            if V13 is None:
                V13 = canonical(CISBN)
            M = parse(HREF)
            v = meta(V13, service = 'wcat', cache ='default')
            GCISDATA = "GCIS-DEV\n\n\t{}\n\n\tisbn_original:{}\n\n\tisbn_mod:{}\n\n" .format(M, ISBNS, V13)
            APIDATA = "WorldCat\n\n\t{}\n\n------------\n\n" .format(v)
            print("GCIS-DEV\n\n\t", M, '\n\n\t', "isbn_original:", ISBNS, '\n\n\t', "isbn_mod:", V13, "\n\n")
            print ("WorldCat\n\n\t", v, '\n\n')
            file2.write(GCISDATA)
            file2.write(APIDATA)

        except:
            Error = '\n\t######## PROBLEM #######\n\tTitle:{}\n\tGCIS-ISBN:{}\n\tIdentifier:{}\n\n'.format(TITLE, ISBNS, IDEN)
            print(Error)
            file.write(Error)

if __name__ =='__main__':
    main()