forked from PSMA/Predictive-to-Building
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflaskApp.py
47 lines (38 loc) · 1.21 KB
/
flaskApp.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
from flask import Flask, request, current_app
import os
import json
import requests
app = Flask(__name__)
with open("api.key", 'r') as key_file:
api_key = key_file.readline().strip()
@app.route("/")
def hello():
return current_app.send_static_file('index.html')
@app.route('/script.js')
def send_js():
return current_app.send_static_file('script.js')
@app.route("/suggest")
def suggest():
addressString = request.args.get('addressString')
url = "https://api.psma.com.au/beta/v1/predictive/address/"
headers = {'authorization': api_key}
params = {
'query' : addressString,
'maxNumberOfResults': 10,
'dataset': 'gnaf'
}
response = requests.request("GET", url, headers=headers, params=params)
return response.text
@app.route("/getBuilding")
def getBuilding():
addressId = request.args.get('addressId')
url = "https://api.psma.com.au/beta/v1/buildings"
headers = {'authorization': api_key}
params = {
'addressId': addressId,
'include': 'footprint2d'
}
response = requests.request("GET", url, headers=headers, params=params)
return response.text
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')