def post(self): book = Book() book.title = self.request.get('title') book.info_url = self.request.get('info_url') book.authors = self.request.get('authors') book.isbn_10 = self.request.get('isbn_10') book.isbn_13 = self.request.get('isbn_13') book.put() self.response.out.write(book.to_json('title', 'authors', 'isbn_10', 'isbn_13', 'is_deleted', 'is_active', 'is_starred'))
def books_add(): form = BookForm(request.form) if request.method == "POST" and form.validate(): new_book = Book(title=form.data.get('title')) new_book.authors = form.data.get('authors') db.session.add(new_book) db.session.commit() flash("Book added") return redirect(url_for('books_view_all')) return render_template('books/add.html', **locals())
def importBook(id): url = 'https://www.googleapis.com/books/v1/volumes/{}'.format(id) print(url) response = requests.get(url) data = response.json() book = Book() if 'title' in data['volumeInfo'].keys(): book.title = data['volumeInfo']['title'] if 'authors' in data['volumeInfo'].keys(): book.authors = str(data['volumeInfo']['authors']) if 'publishedDate' in data['volumeInfo'].keys(): if len(data['volumeInfo']['publishedDate']) > 7: year = data['volumeInfo']['publishedDate'][0:4] month = data['volumeInfo']['publishedDate'][5:7] day = data['volumeInfo']['publishedDate'][8-10] book.publishedDate = datetime(year=int(year), month=int(month), day=int(day)) elif (len(data['volumeInfo']['publishedDate']) < 8) and (len(data['volumeInfo']['publishedDate']) > 4): year = data['volumeInfo']['publishedDate'][0:4] month = data['volumeInfo']['publishedDate'][5:7] book.publishedDate = datetime(year=int(year), month=int(month), day=1) elif len(data['volumeInfo']['publishedDate']) == 4: year = data['volumeInfo']['publishedDate'] book.publishedDate = datetime(year=int(year), month=1, day=1) if 'industryIdentifiers' in data['volumeInfo'].keys(): book.industryIdentifiers = str(data['volumeInfo']['industryIdentifiers']) if 'pageCount' in data['volumeInfo'].keys(): book.pageCount = data['volumeInfo']['pageCount'] if 'imageLinks' in data['volumeInfo'].keys(): for item in data['volumeInfo']['imageLinks'].values(): book.imageLinks = item break; if 'language' in data['volumeInfo'].keys(): book.language = data['volumeInfo']['language'] try: db.session.add(book) db.session.commit() print('Book added successfully!') return redirect(url_for('.books_route')) except: print('Cant add this book!') return redirect(url_for('.books_route'))
def insert(): if request.method == 'POST': isbn = request.form['isbn'] googleApi = GoogleApi(isbn) googleApi.get_data() book = Book(isbn) book.title = googleApi.title book.authors = googleApi.authors book.authors = googleApi.authors db.session.add(book) db.session.commit() return redirect(url_for('home')) return render_template("insert.html")
def edit_book(id): '''Editing or adding new book depends on given id.''' if id == 'new': book = Book() else: book = Book.query.filter_by(id=id).first_or_404() form = BookForm(request.form, obj=book) if request.method == 'GET': return render_template('edit_book.html', form=form) if request.method == 'POST' and form.validate(): form.populate_obj(book) book.title = form.title.data book.authors = form.authors.data if id == 'new': db.session.add(book) flash('Book was successfully added') else: db.session.merge(book) flash('Book was successfully updated') db.session.commit() return redirect(url_for('book', id=book.id)) else: return render_template('edit_book.html', form=form)
def add_route(): form = AddBookForm() if form.validate_on_submit(): book = Book() book.title = form.title.data authors = str(form.authors.data).split(',') book.authors = str(authors) book.publishedDate = form.publishedDate.data identifiers = str(form.industryIdentifiers.data).split(',') listOfDicts = [] for identifier in identifiers: listOfItems = identifier.split(':') dictItems = {} dictItems['type'] = listOfItems[0] dictItems['identifier'] = listOfItems[1] listOfDicts.append(dictItems) book.industryIdentifiers = str(listOfDicts) book.pageCount = form.pageCount.data book.imageLinks = form.imageLinks.data book.language = form.language.data try: db.session.add(book) db.session.commit() print('Book added successfully!') return redirect(url_for('/books')) except: print('Cant add this book!') return render_template('add.html', form = form)
def scan(self): try: if sys.platform == 'win32': ZBARPATH = list(which('zbarcam')) if not ZBARPATH: ZBARPATH = list(which('zbarcam', path=[r"C:\Program Files\ZBar\bin", r"C:\Program Files (x86)\ZBar\bin"]))[0] else: ZBARPATH = list(which('zbarcam'))[0] except: ZBARPATH = None if not ZBARPATH: QtGui.QMessageBox.information(None, "Aranduka - Error", "Can't find zbarcam. Get it at http://zbarcam.sf.net") return p=os.popen(ZBARPATH,'r') p = subprocess.Popen([ZBARPATH], stdout=subprocess.PIPE).communicate()[0] # p = "DEMO:0345400445" guesser = manager.getPluginsOfCategory('Guesser')[0] for code in p.splitlines(): print("scanning") if code: print(('Got barcode:', code)) isbn = code.split(':')[1] # QtGui.QDesktopServices.openUrl(QtCore.QUrl('http://www.goodreads.com/search/search?q=%s'%isbn)) i = Identifier(key='ISBN', value=isbn) # Create empty book b = Book(identifiers = [i]) # We are supposed to have a ISBN, so assume we are getting it right. dlg = GuessDialog(b) dlg.isbn.setChecked(True) dlg.on_guessButton_clicked() r = dlg.exec_() # FIXME this is copied from book_editor. # The Book class probably needs an "update from metadata" method. md = None if not r == dlg.Accepted: md = None b.delete() elif dlg.currentMD: md = dlg.currentMD if md is None: return else: # A candidate was chosen, update data print(md) b.title = md.title if md.identifiers is not None: for k,v in md.identifiers: i = Identifier( key=k.upper(), value=v, book=b) b.authors = [] for a in md.authors: author = Author.get_by(name = a) if not author: print(("Creating author:", a)) author = Author(name = a) b.authors.append(author) Author.sanitize() # FIXME: it seems Qt can't parse alibris cover images? # b.fetch_cover(md.thumbnail) b.fetch_cover() session.commit()