コード例 #1
0
ファイル: views.py プロジェクト: cshinaver/BookFinder
        bv = BooksViewed()
        bv.user_id = user_id
        bv.book_id = book.id
        bv.save()
        return 'Book View added successfully', 201

    return 'Book View already exists', 200


@app.route('/api/comparison_option_list/')
def comparison_option_query():
    isbn = request.args.get('isbn')
    option_list = []
    amazon_list = AmazonScraper().get_amazon_purchase_choices_for_keyword(isbn)
    option_list.extend(amazon_list)
    barnes_list = get_Barnes_book_prices_for_isbn(isbn)
    if barnes_list is not None:
        for option in barnes_list:
            option_list.append(option.to_dict())
    google_list = get_google_books_for_isbn(isbn)
    if google_list is not None:
        for option in google_list:
            option_list.append(option.to_dict())
    json_output = json.dumps(option_list, sort_keys=True, indent=4)
    return json_output

app.add_url_rule(
    '/api/used_option_list/',
    view_func=UsedOptionList.as_view('used_option_list'),
)
コード例 #2
0
ファイル: views.py プロジェクト: cshinaver/BookFinder
    def get_book_from_isbn(self, isbn):
        errors = []
        book = get_books_for_book_title_using_google_books('isbn:' + isbn)
        if not book:
            errors.append('ISBN is invalid')
        return book, errors

    def form_error_checking(self, isbn, price):
        errors = []
        if isbn == '':
            errors.append('No ISBN entered')
        if price == '':
            errors.append('No price entered')
        if len(price) > 10:
            errors.append('Price must not exceed 10 characters')
        len_isbn = len(isbn)
        if len_isbn != 10 and len_isbn != 13:
            errors.append(
                'ISBN has incorrect number of characters. '
                'Please enter ISBN-10 or ISBN-13'
            )
        return errors

    def redirect_to_self_with_errors(self, errors):
        for error in errors:
            flash(error, 'error')
        return redirect(url_for('sell_book'))


app.add_url_rule('/purchase/', view_func=SellBook.as_view('sell_book'))