-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (37 loc) · 1.12 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask ,request, jsonify
from sqlalchemy import Integer, Enum
from flask_sqlalchemy import SQLAlchemy
from flask_heroku import Heroku
from flask_cors import CORS,cross_origin
from flask.helpers import send_from_directory
import enum
import datetime
import os
import re
import requests
import json
# Instanciate the app
app=Flask(__name__,static_folder='brewery/build',static_url_path='')
CORS(app)
# rest api that implements the search functionality.
@app.route("/breweries/search",methods=["GET"])
@cross_origin()
def home():
list = request.args.get('query', None)
if(list):
url='https://api.openbrewerydb.org/breweries/search?query='+ str(list)
breweries=requests.get(url)
data=breweries.content
l=[]
brew=json.loads(data)
brew2=json.loads(data)
for i in range(len(brew2)):
brew[i]=dict(brew[i])
return jsonify(brew)
#used by heroku so that the build can be identified
@app.route('/')
def serve():
return send_from_directory(app.static_folder, 'index.html')
if __name__ == "__main__":
app.debug=True
app.run()