Example #1
0
def get_book(isbn):
    book_info = meta(isbn)
    if book_info:
        book = Book(
            isbn=book_info.get('ISBN-13', ""),
            title=book_info.get('Title', ""),
            authors=book_info.get('Authors', ""),
            year=book_info.get('Year', "")
        )
        return book
    else:
        raise BookpyError("Could not retrieve information about the isbn. Check your Internet connection.")
Example #2
0
def get_data(line):
    """
    Method to take the data from the MYSQL server and
    convert it from
    Type:       BOOK
    Title:      Why Should I Recycle
    Author:     Jen Green
    Author:     Mike Gordon
    ISBN:       9780764131554
    Year:       2005
    Publisher:  Barons Juveniles

    Into a dictionary to make data easily transferable
    {
        'Author': ['Jen Green', 'Mike Gordon'],
        'Type': 'BOOK',
        'Title': 'Why Should I Recycle?',
        'ISBN': '9780764131554',
        'Year': '2005',
        'Publisher': 'Barrons Juveniles'
    }

    :param line:
    :return:
    """
    # Book data dictionary
    book_data = {}

    # Using the isbntools.app, perform the query
    data_collected = registry.bibformatters['labels'](meta(line))

    # This is meant to be an echo to make sure the request
    # is what we were looking for
    # print(data_collected)

    # Split the data at the new lines
    iterated_data = data_collected.split("\n")
    # Type:BOOK

    # This is for authors, since there can be multiple
    book_data["Author"] = []

    # Loops through the data collected for the book
    # and converts it into a dictionary
    for data in iterated_data:
        if data.split(":")[0].strip() == "Author":
            book_data["Author"].append(data.split(":")[1].strip())
        else:
            book_data[data.split(":")[0].strip()] = data.split(":")[1].strip()
    print(book_data)
    return book_data
Example #3
0
 def add(self, ISBN):
     '''Add books to the current working database
         Usage:-
         add(ISBN) or add ISBN'''
     if _doesexist(self.db, ISBN) == False:
         try:
             bookData = meta(ISBN)
             bookData = _cleanify(bookData)
             bookData['Date Added'] = _today()
             self.db.insert(bookData)
             print 'ISBN {} inserted'.format(ISBN)
         except:
             print 'ISBN {} not found. Please add details manually- '.format(ISBN)
             self.madd()
     else:
         print 'Book Already Exists'
Example #4
0
 def add(self, ISBN):
     '''Add books to the current working database
         Usage:-
         add(ISBN) or add ISBN'''
     if _doesexist(self.db, ISBN) == False:
         try:
             bookData = meta(ISBN)
             bookData = _cleanify(bookData)
             bookData['Date Added'] = _today()
             self.db.insert(bookData)
             print 'ISBN {} inserted'.format(ISBN)
         except:
             print 'ISBN {} not found. Please add details manually- '.format(
                 ISBN)
             self.madd()
     else:
         print 'Book Already Exists'
Example #5
0
def _make_isbn(isbn_no):

    meta_dict = app.meta(isbn_no)
    if meta_dict:
        if meta_dict.get('Title'):
            try:
                isbn = Isbn.objects.get(code=isbn_no)
            except ObjectDoesNotExist:
                isbn = Isbn(code=isbn_no,
                            title=meta_dict.get('Title'),
                            publisher=meta_dict.get('Publisher'),
                            year=date(2001, 1, 1))
                isbn.save()
            for a in meta_dict.get('Authors'):
                try:
                    author = Author.objects.get(name=a)
                except ObjectDoesNotExist:
                    author = Author.objects.create(name=a)
                isbn.authors.add(author)
Example #6
0
def _make_isbn(isbn_no):

    meta_dict = app.meta(isbn_no)
    if meta_dict:
        if meta_dict.get('Title'):
            try:
                isbn = Isbn.objects.get(code=isbn_no)
            except ObjectDoesNotExist:
                isbn = Isbn(code=isbn_no,
                            title=meta_dict.get('Title'),
                            publisher=meta_dict.get('Publisher'),
                            year=date(2001, 1, 1)
                            )
                isbn.save()
            for a in meta_dict.get('Authors'):
                try:
                    author = Author.objects.get(name=a)
                except ObjectDoesNotExist:
                    author = Author.objects.create(name=a)
                isbn.authors.add(author)
Example #7
0
def wrapper(isbn, genre=True):
    try:
        ddc_scraper = AutoDDC()
        ddc_scraper.find_in_url(ddc_scraper.ddc_urlwrapper(isbn))
        ddc = ddc_scraper.pretty_ddc()
        current_page = ddc_scraper.getter.page

        if genre:
            genre = ddc_scraper.summaries[str(int(float(ddc)))]
            try:
                metadata = meta(str(isbn))
                title, author = metadata['Title'], metadata['Authors'][0]
            except:
                metadata = get_title_author(current_page)
                title, author = metadata

            return OrderedDict([('DDC', ddc), ('Title', title),
                                ('Author', author), ('Genre', genre)])
        return ddc
    except ConnectionError:
        return ('Internet Not Connected')
    except AttributeError:
        return (f'No Entry for {isbn}')
from isbntools import app
import isbnlib
import argparse

parser = argparse.ArgumentParser(description='ISBN Lookup')
parser.add_argument('ISBN')
args = parser.parse_args()

app.config.add_apikey('isbndb', 'VHH8GLVV')
meta_dict = app.meta(args.ISBN)
print meta_dict
if meta_dict:
    print isbnlib.registry.bibformatters['json'](meta_dict)

Example #9
0
 if (len(myisbn) == 9):
     myisbn1 = myisbn + 'x'
     print('>>invalid ISBN: %s shifted to: %s' % (myisbn, myisbn1))
 else:
     myisbn1 = myisbn
 cur = conn.execute("select Title from book_info where ISBN='%s';" %
                    (myisbn))
 tpr = cur.fetchall()
 #pdb.set_trace()
 if tpr[0][0] != 'nan':
     print('>>%s%s already in DB, skipping!' % (progr, myisbn))
 else:
     try:
         # if index==3:
         #     pdb.set_trace()
         bookinfo = meta(myisbn1)
         descp = desc(myisbn1)
         aut = ', '.join(bookinfo['Authors'])
         #pdb.set_trace()
         conn.execute(
             'update book_info set Title=:title, Authors=:authors, Year=:year, ISBN13=:isbn13, Publisher=:publisher, Description=:description where ISBN=:isbn;',
             {
                 'title': bookinfo['Title'],
                 'authors': aut,
                 'year': bookinfo['Year'],
                 'isbn13': bookinfo['ISBN-13'],
                 'publisher': bookinfo['Publisher'],
                 'description': descp,
                 'isbn': myisbn,
             })
         #conn.execute('select * from book_info where ISBN="0131177052"').fetchall()