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})
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)
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'
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
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
def test(isbnx): book = isbnlib.meta(isbnx) data = isbnlib.cover(isbnx) try: return data['thumbnail'] except: print("Handled error ")
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=[])
def return_img(ISBN): try: img = isbnlib.cover(ISBN)['smallThumbnail'] except: img = 'http://google.com/favicon.ico' print(img) return img
def datahunt(isbnSearch): searchTerm = isbnSearch isbn = isbnlib.isbn_from_words(searchTerm) returnData = isbnlib.meta(isbn) cover = isbnlib.cover(isbn) #print("Cover: ", cover) try: mainTitle = returnData["Title"] except Exception as e: mainTitle = "" try: mainAuthors = returnData["Authors"] except Exception as e: mainAuthors = "" try: mainPublisher = returnData["Publisher"] except Exception as e: mainPublisher = "" try: mainYear = returnData["Year"] except Exception as e: mainYear = "" try: mainISBN = returnData["ISBN-13"] except Exception as e: mainISBN = "" try: mainCover = cover["smallThumbnail"] except Exception as e: mainCover = "" bookInfo = { "title" : mainTitle, "author" : mainAuthors, "publisher" : mainPublisher, "year" : mainYear, "isbn" : mainISBN, "coverURL" : mainCover } return bookInfo
def setMetadata(self): try: self.isbn = isbnlib.isbn_from_words(f"{self.title+self.author}") self.save() try: self.imageURL = isbnlib.cover(self.isbn)['thumbnail'] self.save() except KeyError as coverError: print(f"cover error -> {self.title}") except (IndexError, TypeError, UnboundLocalError) as isbnError: print(f"isbn error -> {self.title}")
def add_book(): form = AddBookForm() if form.validate_on_submit(): isbn = request.form['isbn'] if isbnlib.is_isbn13(isbn): isbn = isbnlib.to_isbn10(isbn) if not isbnlib.is_isbn10(isbn): flash('Enter valid ISBN', 'error') return redirect(url_for('admin_page.add_book')) book_data = isbnlib.meta(isbn) book_cover = isbnlib.cover(isbn)
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)
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)
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
async def cover(ctx, isbn: str): """Fetch an image of the cover for a book. Args: isbn: ISBN number of the you'd like the cover of. """ if await channel_check(ctx): try: cover_url = isbnlib.cover(isbn)['smallThumbnail'] url_hash = str(hash(cover_url)) + '.jpg' urllib.request.urlretrieve(cover_url, url_hash) with open(url_hash, 'rb') as f: picture = discord.File(f) await ctx.send(file=picture) os.remove(url_hash) except KeyError: await respond(ctx, [ "Sorry, we couldn't find an image of that book's cover " + random.choice(SAD_EMOJI) ])
def getCoverSmall(isbn): cover = isbnlib.cover(isbn) if cover != None: return cover['smallThumbnail']
from isbnlib import meta, cover from isbnlib.config import add_apikey import os try: proxy = 'http://172.16.2.30:8080' os.environ['http_proxy'] = proxy os.environ['HTTP_PROXY'] = proxy os.environ['https_proxy'] = proxy os.environ['HTTPS_PROXY'] = proxy os.environ['NO_PROXY'] = 'localhost,127.0.0.1/*,127.0.0.1' except: print("proxy error") SERVICE = 'isbndb' APIKEY = 'temp475675837' # <-- replace with YOUR key # register your key add_apikey(SERVICE, APIKEY) isbn = '9780141199610' book = meta(isbn) print(book) print(cover(isbn))
def getCover(isbn): cover = isbnlib.cover(isbn) if cover != None: return cover['thumbnail']
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))
def __init__(self, isbn): self.data_book = meta(isbn) self.data_book['Desc'] = desc(isbn) self.data_book['Images'] = cover(isbn)
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))
def com_isbn_cover(isbn_string): """ Returns a dictionary with the url for cover.Almost all data available are for US books! """ return isbnlib.cover(isbn_string)
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))
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)