-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_2_basic.py
32 lines (23 loc) · 870 Bytes
/
api_2_basic.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
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
data = request.get_json()
name = data.get('name')
message = 'Hello {}!'.format(name)
return jsonify({'message': message})
else: # GET
return jsonify({'message': 'hello from flask API!'})
# {'city': 'temp'}
temperature = {'Gaza': 23, 'Tripoli': 26, 'Alexandria': 24,
'Izmir': 22, 'Istanbul': 19, 'Athens': 20,
'Napoli': 20, 'Genova': 18, 'Marseille': 17,
'Barcelona': 18, 'Casablanca': 20, 'Oran': 24,
'Bizerte': 17, 'Rafah': 23, 'Khanyounis': 30}
@app.route('/weather/<city>')
def get_temp(city):
temp = temperature.get(city)
return jsonify({'temp': temp})
if __name__ == '__main__':
app.run()