diff options
-rw-r--r-- | Dockerfile | 6 | ||||
-rw-r--r-- | app.py | 23 | ||||
-rw-r--r-- | data/beers.json (renamed from static/beers.json) | 0 | ||||
-rw-r--r-- | requirements.txt | 6 | ||||
-rw-r--r-- | templates/Homepage.jinja2 | 24 | ||||
-rw-r--r-- | templates/beerpage.jinja2 | 8 | ||||
-rw-r--r-- | templates/random_beer.jinja2 | 9 | ||||
-rw-r--r-- | templates/similar.jinja2 | 9 |
8 files changed, 61 insertions, 24 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..73af964 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3-alpine +WORKDIR /usr/src/app +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt +COPY . . +CMD ["python", "app.py"] @@ -6,27 +6,31 @@ import re app = Flask(__name__) -with open("./static/beers.json") as beers_json: +with open("./data/beers.json") as beers_json: beer = json.loads(beers_json.read()) - @app.route('/') -def hello_world(): - hello_beer = random.choice(list(beer.keys())) - return render_template('Homepage.jinja2', item=beer[hello_beer]) +def index(): + return render_template('Homepage.jinja2', suggestions=all_beer_names()) + +@app.route('/random') +def random_beer(): + rando = random.choice(list(beer.keys())) + return render_template('random_beer.jinja2', beer=beer[rando]) +@app.route('/similar', methods=['POST']) +def similar(): + return render_template('similar.jinja2', beers=[]) @app.route('/brewery/<brewery_id>/') def get_brewery_list(brewery_id): return json.dumps(find_beers_from_brewery(brewery_id)) - @app.route('/brewery/<brewery_id>/<beer_id>') def get_beer_details(brewery_id, beer_id): beer_result = beer_lookup(brewery_id,beer_id) return render_template('beerpage.jinja2', beer_data=beer_result) - def beer_lookup(brewery_id, beer_id): item_id = brewery_id + "-" + beer_id try: @@ -35,17 +39,17 @@ def beer_lookup(brewery_id, beer_id): except: return None +def all_beer_names(): + return [value[0] for key, value in beer.items()] def find_beers_from_brewery(brewery_id): pattern = re.compile('^' + brewery_id + '-.*') beers = [value for key, value in beer.items() if pattern.match(key)] return beers - if __name__ == '__main__': app.run() - class BeerInfo(object): def __init__(self, item_json): @@ -54,7 +58,6 @@ class BeerInfo(object): self.name = item_json[0] self.abv = item_json[2] - class Brewery(object): def __init__(self, id): self.id = id diff --git a/static/beers.json b/data/beers.json index fa53720..fa53720 100644 --- a/static/beers.json +++ b/data/beers.json diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..36f710e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +Click==7.0 +Flask==1.1.1 +itsdangerous==1.1.0 +Jinja2==2.10.1 +MarkupSafe==1.1.1 +Werkzeug==0.15.5 diff --git a/templates/Homepage.jinja2 b/templates/Homepage.jinja2 index cad512e..191d591 100644 --- a/templates/Homepage.jinja2 +++ b/templates/Homepage.jinja2 @@ -1,16 +1,12 @@ {% extends "base.html" %} {% block content %} -<h3> {{ item[0] }}</h3> -<div> - <ul> - <li> - Beer Parent: {{ item[1][0] }} - </li> - <li> - SubType: {{ item[1][1] }} - </li> - </ul> - <br/> - How Blasted is I be: {{ item[2] }} -</div> -{% endblock %}
\ No newline at end of file +<h1>SimilarBeer</h1> +<form action="/similar" method="post"> + <div> + <label for="q"><strong>Tell us a beer you like:</strong></label><br> + <input type="text" id="q" list="beers" autofocus> + </div> + <input type="submit" value="Show me others!"> +</form> +<p><a href="/random">Random Beer</a></p> +{% endblock %} diff --git a/templates/beerpage.jinja2 b/templates/beerpage.jinja2 index f743d1b..65b9fb1 100644 --- a/templates/beerpage.jinja2 +++ b/templates/beerpage.jinja2 @@ -17,4 +17,12 @@ </tr> </table> </div> + <div id="machine"> + <select> + {% for item in beer_data['attributes']%} + <option>{{ item['name'] }}</option> + + {% endfor %} + </select> + </div> {% endblock %}
\ No newline at end of file diff --git a/templates/random_beer.jinja2 b/templates/random_beer.jinja2 new file mode 100644 index 0000000..294a5b7 --- /dev/null +++ b/templates/random_beer.jinja2 @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} +<p>How about a nice</p> +<h1>{{ beer[0] }}</h1> +<p>Parent: {{ beer[1][0] }}</p> +<p>Subtype: {{ beer[1][1] }}</p> +<p>Blast: {{ beer[2] }}</p> +<p><a href="/random">Another!</a></p> +{% endblock %} diff --git a/templates/similar.jinja2 b/templates/similar.jinja2 new file mode 100644 index 0000000..b7a57f7 --- /dev/null +++ b/templates/similar.jinja2 @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} +<h1>Similar Beers</h1> +<ul> +{% for beer in beers %} + <li>{{ beer }}</li> +{% endfor %} +</ul> +{% endblock %} |