aboutsummaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'app.py')
-rw-r--r--app.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/app.py b/app.py
new file mode 100644
index 0000000..91b5d83
--- /dev/null
+++ b/app.py
@@ -0,0 +1,58 @@
+from flask import Flask
+import json
+import random
+import re
+
+app = Flask(__name__)
+
+with open("./static/beers.json") as beers_json:
+ beer = json.loads(beers_json.read())
+
+
+@app.route('/')
+def hello_world():
+ hello_beer = random.choice(list(beer.keys()))
+ return json.dumps({hello_beer:beer[hello_beer]})
+
+
+@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):
+ return json.dumps(beer_lookup(brewery_id, beer_id))
+
+
+def beer_lookup(brewery_id, beer_id):
+ item_id = brewery_id + "-" + beer_id
+ return beer[item_id]
+
+
+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):
+ self.parent_style = item_json[1][1]
+ self.base_style = item_json[1][0]
+ self.name = item_json[0]
+ self.abv = item_json[2]
+
+
+class Brewery(object):
+ def __init__(self, id):
+ self.id = id
+ self.brews = []
+
+ def add_brew(self, brew):
+ self.brews.append(brew)