def index(): # if someone visits the site, (GET request), show them the list of books if request.method == 'GET': author = request.args.get("author", None) # These render_template calls compile the data with the template at \templates\index.html if author: return render_template('index.html', author=author, books=Book.objects(read=False).order_by("-year")) return render_template('index.html', books=Book.objects(read=False).order_by("-year")) # handle an add author request elif request.method == 'POST': author = request.form['author'] year = request.form['year'] # Add the author to the database and reload the page Author(name=author, year=year).save() return redirect('/')
def main(): for author in Author.objects: books = scrape_author(author.name, author.year) for book in books: year = book[0] title = book[1].encode('ascii', 'ignore') link = book[2] if not Book.objects(author=author.name, title=title, year=year).count(): Book(author=author.name, title=title, link=link, year=year, read=False).save()
def mark_complete(): the_id = request.args.get('id') # Add the book to the database and reload the page Book.objects(id=the_id).update(set__read=True) return redirect('/')