-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
42 lines (26 loc) · 887 Bytes
/
hello.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
import requests, json
from flask import Flask, request, render_template, jsonify
app = Flask(__name__)
DATA_SOURCE = "http://data.sfgov.org/resource/rqzj-sfat.json"
def pretty(json_str):
return json.dumps(json_str, sort_keys=True, indent=2, separators=(',', ': '))
def sekitar_embarcadero(truck):
return truck.get('x') > 1 and truck.get('y') > 1
def applicant_x_y(truck):
return {
'Food truck name': truck.get('applicant'),
'x': truck.get('x'),
'y': truck.get('y')
}
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/test')
def test():
d = requests.get(DATA_SOURCE)
json_data = d.json()
approved = filter(sekitar_embarcadero, json_data)
applicants = map(applicant_x_y, approved)
return pretty(applicants)
if __name__ == '__main__':
app.run(debug=True)