aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Cohen <ben@kensho.com>2019-07-28 16:24:38 -0400
committerBen Cohen <ben@kensho.com>2019-07-28 16:24:38 -0400
commitd23fa5cda7eb9368c843fa02b6e2b04f08293673 (patch)
tree85c7d8d09a1c1fa13299ac47ee394306ad3affec
parente4528da4b13e6e84aa961944850efbe28e3773be (diff)
parent1c16cfceca3134b79b9319a3b4d467972dc5989f (diff)
pull
-rw-r--r--app.py34
-rw-r--r--templates/beerpage.jinja2166
2 files changed, 172 insertions, 28 deletions
diff --git a/app.py b/app.py
index e06b2d7..4089579 100644
--- a/app.py
+++ b/app.py
@@ -3,7 +3,7 @@ from flask import render_template
from flask import redirect
from flask import request
from flask import url_for
-from utils import get_closest, translate_to_attr, get_style_preds
+from utils import get_closest, translate_to_attr, get_style_preds, translate_to_style
import json
import random
import re
@@ -77,16 +77,28 @@ def get_beer_details(brewery_id, beer_id):
similar_beer_objects.append(BeerInfo(item, item_brewer, item_result))
if request.method == 'POST':
- attr = request.form['attr']
- direction = request.form['direction']
- attr_beers = translate_to_attr(full_id, attr, int(direction))
- attr_beer_objects = []
- for item in attr_beers:
- item_result, item_brewer = beer_lookup(item[0])
- attr_beer_objects.append(BeerInfo(item[0], item_brewer, item_result))
- return render_template('beerpage.jinja2', beer_data=beerinfo,
- attrs=ATTRS, similar_beers=similar_beer_objects, attr=attr,
- direction=direction, attr_beers=attr_beer_objects, style_preds=similar_beers)
+
+ attr = request.form.get('attr')
+ direction = request.form.get('direction')
+ style = request.form.get('style')
+ if attr != None and direction != None:
+ attr_beers = translate_to_attr(full_id, attr, int(direction))
+ attr_beer_objects = []
+ for item in attr_beers:
+ item_result, item_brewer = beer_lookup(item[0])
+ attr_beer_objects.append(BeerInfo(item[0], item_brewer, item_result))
+ return render_template('beerpage.jinja2', beer_data=beerinfo,
+ attrs=attrs, similar_beers=similar_beer_objects, attr=attr,
+ direction=direction, attr_beers=attr_beer_objects, style_preds=similar_beers)
+ if style != None:
+ style_beers = translate_to_style(full_id, style)
+ style_beer_objects = []
+ for item in style_beers:
+ item_result, item_brewer = beer_lookup(item[0])
+ style_beer_objects.append(BeerInfo(item[0], item_brewer, item_result))
+ return render_template('beerpage.jinja2', beer_data=beerinfo,
+ attrs=attrs, similar_beers=similar_beer_objects,
+ style=style, style_beers=style_beer_objects, style_preds=similar_beers)
return render_template('beerpage.jinja2', beer_data=beerinfo, attrs=ATTRS,
similar_beers=similar_beer_objects, style_preds=similar_beers)
diff --git a/templates/beerpage.jinja2 b/templates/beerpage.jinja2
index 68291af..aa45409 100644
--- a/templates/beerpage.jinja2
+++ b/templates/beerpage.jinja2
@@ -80,23 +80,146 @@ function drawAnnotations() {
{% endfor %}
</ul>
- <form action="" method="post" class="form-inline alert alert-secondary">
- Show me beers which are
- <select name="direction" class="form-control">
- <option {% if direction == '3' %}selected{% endif %} value="3">Much more</option>
- <option {% if direction == '2' %}selected{% endif %} value="2">More</option>
- <option {% if direction == '1' %}selected{% endif %} value="1">Little more</option>
- <option {% if direction == '-1' %}selected{% endif %} value="-1">Little less</option>
- <option {% if direction == '-2' %}selected{% endif %} value="-2">Less</option>
- <option {% if direction == '-3' %}selected{% endif %} value="-3">Much less</option>
- </select>
- <select name="attr" class="form-control">
- {% for a in attrs %}
- <option {% if a == attr %}selected{% endif %} value="{{ a }}">{{ a }}</option>
- {% endfor %}
- </select>
- <input type="submit" value="Go" class="btn btn-outline-primary">
- </form>
+ <div class="row">
+ <div class="col">
+ <form action="" method="post" class="alert alert-secondary form-inline">
+ Show me beers which are
+ <select name="direction" class="form-control">
+ <option {% if direction == '3' %}selected{% endif %} value="3">Much more</option>
+ <option {% if direction == '2' %}selected{% endif %} value="2">More</option>
+ <option {% if direction == '1' %}selected{% endif %} value="1">Little more</option>
+ <option {% if direction == '-1' %}selected{% endif %} value="-1">Little less</option>
+ <option {% if direction == '-2' %}selected{% endif %} value="-2">Less</option>
+ <option {% if direction == '-3' %}selected{% endif %} value="-3">Much less</option>
+ </select>
+ <select name="attr" class="form-control">
+ {% for a in attrs %}
+ <option {% if a == attr %}selected{% endif %} value="{{ a }}">{{ a }}</option>
+ {% endfor %}
+ </select>
+ <input type="submit" value="Go" class="btn btn-outline-primary">
+ </form>
+ </div>
+ <div class="col">
+ <form action="" method="post" class="alert alert-secondary form-inline">
+ Show me similar beers in the style of
+ <select name="style" class="form-control">
+ <option>German Bock</option>
+ <option>German Doppelbock</option>
+ <option>German Eisbock</option>
+ <option>German Maibock</option>
+ <option>German Weizenbock</option>
+ <option>American Brown Ale</option>
+ <option>English Brown Ale</option>
+ <option>English Dark Mild Ale</option>
+ <option>German Altbier</option>
+ <option>American Black Ale</option>
+ <option>Belgian Dark Ale</option>
+ <option>Belgian Dubbel</option>
+ <option>German Roggenbier</option>
+ <option>Scottish Ale</option>
+ <option>Winter Warmer</option>
+ <option>American Amber / Red Lager</option>
+ <option>European Dark Lager</option>
+ <option>German Märzen / Oktoberfest</option>
+ <option>German Rauchbier</option>
+ <option>German Schwarzbier</option>
+ <option>Munich Dunkel Lager</option>
+ <option>Vienna Lager</option>
+ <option>American Cream Ale</option>
+ <option>Bière de Champagne / Bière Brut</option>
+ <option>Braggot</option>
+ <option>California Common / Steam Beer</option>
+ <option>American Brut IPA</option>
+ <option>American Imperial IPA</option>
+ <option>American IPA</option>
+ <option>Belgian IPA</option>
+ <option>English India Pale Ale (IPA)</option>
+ <option>New England IPA</option>
+ <option>American Amber / Red Ale</option>
+ <option>American Blonde Ale</option>
+ <option>American Pale Ale (APA)</option>
+ <option>Belgian Blonde Ale </option>
+ <option>Belgian Pale Ale</option>
+ <option>Belgian Saison</option>
+ <option>English Bitter</option>
+ <option>English Extra Special / Strong Bitter (ESB)</option>
+ <option>English Pale Ale</option>
+ <option>English Pale Mild Ale</option>
+ <option>French Bière de Garde</option>
+ <option>German Kölsch</option>
+ <option>Irish Red Ale</option>
+ <option>American Adjunct Lager</option>
+ <option>American Imperial Pilsner</option>
+ <option>American Lager</option>
+ <option>American Light Lager</option>
+ <option>American Malt Liquor</option>
+ <option>Bohemian Pilsener</option>
+ <option>European Export / Dortmunder</option>
+ <option>European Pale Lager</option>
+ <option>European Strong Lager</option>
+ <option>German Helles</option>
+ <option>German Kellerbier / Zwickelbier</option>
+ <option>German Pilsner</option>
+ <option>American Imperial Porter</option>
+ <option>American Porter</option>
+ <option>Baltic Porter</option>
+ <option>English Porter</option>
+ <option>Robust Porter </option>
+ <option>Smoke Porter</option>
+ <option>Chile Beer</option>
+ <option>Finnish Sahti</option>
+ <option>Fruit and Field Beer</option>
+ <option>Herb and Spice Beer</option>
+ <option>Japanese Happoshu</option>
+ <option>Japanese Rice Lager</option>
+ <option>Low Alcohol Beer</option>
+ <option>Pumpkin Beer</option>
+ <option>Russian Kvass</option>
+ <option>Rye Beer</option>
+ <option>Scottish Gruit / Ancient Herbed Ale</option>
+ <option>Smoke Beer</option>
+ <option>American Imperial Stout</option>
+ <option>American Stout</option>
+ <option>English Oatmeal Stout</option>
+ <option>English Stout</option>
+ <option>English Sweet / Milk Stout</option>
+ <option>Foreign / Export Stout</option>
+ <option>Irish Dry Stout</option>
+ <option>Russian Imperial Stout</option>
+ <option>American Barleywine</option>
+ <option>American Imperial Red Ale</option>
+ <option>American Strong Ale</option>
+ <option>American Wheatwine Ale</option>
+ <option>Belgian Quadrupel (Quad)</option>
+ <option>Belgian Strong Dark Ale</option>
+ <option>Belgian Strong Pale Ale</option>
+ <option>Belgian Tripel</option>
+ <option>British Barleywine</option>
+ <option>English Old Ale</option>
+ <option>English Strong Ale</option>
+ <option>Scotch Ale / Wee Heavy</option>
+ <option>American Dark Wheat Ale</option>
+ <option>American Pale Wheat Ale</option>
+ <option>Belgian Witbier</option>
+ <option>Berliner Weisse</option>
+ <option>German Dunkelweizen</option>
+ <option>German Hefeweizen</option>
+ <option>German Kristalweizen</option>
+ <option>American Brett",
+ <option>American Wild Ale",
+ <option>Belgian Faro",
+ <option>Belgian Fruit Lambic",
+ <option>Belgian Gueuze",
+ <option>Belgian Lambic",
+ <option>Flanders Oud Bruin",
+ <option>Flanders Red Ale",
+ <option>Leipzig Gose",
+ </select>
+ <input type="submit" value="Go" class="btn btn-outline-primary">
+ </form>
+ </div>
+ </div>
{% if attr_beers %}
<h5>Beers like {{ beer_data.name }} but {{ direction }} {{ attr }}</h5>
@@ -107,4 +230,13 @@ function drawAnnotations() {
</ul>
{% endif %}
+ {% if style_beers %}
+ <h5>Beers like {{ beer_data.name }} but in the {{ style }} style</h5>
+ <ul>
+ {% for style_beer in style_beers %}
+ <li><a href="{{ style_beer.link }}" >{{ style_beer.name }}</a></li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
{% endblock %}