-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jar2333/books
Books route
- Loading branch information
Showing
11 changed files
with
83 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
from flask import Flask | ||
from flask import Flask, request, render_template, jsonify | ||
Check failure on line 1 in app.py GitHub Actions / buildRuff (F401)
|
||
from flask_caching import Cache | ||
|
||
from env import GOODREADS_URL | ||
|
||
from src.book_scraper import BookScraper | ||
|
||
""" | ||
Mounts a prefix for all routes | ||
""" | ||
SCRIPT_NAME = "/api" | ||
|
||
""" | ||
Scraper for book API | ||
""" | ||
SCRAPER = BookScraper(GOODREADS_URL) | ||
|
||
""" | ||
App configuration | ||
""" | ||
config = { | ||
"DEBUG": True, # some Flask specific configs | ||
"CACHE_TYPE": "SimpleCache", # Flask-Caching related configs | ||
"CACHE_DEFAULT_TIMEOUT": 300 | ||
} | ||
|
||
""" | ||
The main application | ||
""" | ||
app = Flask(__name__) | ||
app.config.from_mapping(config) | ||
|
||
cache = Cache(app) | ||
|
||
@app.route("/") | ||
def root(): | ||
return "Hello World!" | ||
@app.route("/books") | ||
@cache.cached(timeout=86400) | ||
def get_books(): | ||
results = SCRAPER.scrape() | ||
return render_template("books.html", results=results), 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import os | ||
|
||
GOODREADS_URL = os.environ.get('GOODREADS_URL') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div id="books"> | ||
{% for result in results %} | ||
<div class="book"> | ||
<img alt="{{result['title']}}" src="{{result['image_url']}}"> | ||
<a href="{{result['url']}}"><p>{{result['title']}}</p></a> | ||
<a href="{{result['author_url']}}"><p>By {{result['author']}}</p></a> | ||
<p>Progress: {{result['progress']}}%</p> | ||
</div> | ||
{% endfor %} | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters