forked from bstocker/flask_hello_world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
39 lines (31 loc) · 1.67 KB
/
__init__.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
from flask import Flask, render_template_string, render_template, jsonify
from flask import render_template
from flask import json
from urllib.request import urlopen
import sqlite3
app = Flask(__name__)
@app.route('/')
def hello_world():
return render_template('hello.html')
@app.route("/fr/")
def monfr():
return "<h2>Bonjour tout le monde !</h2>"
@app.route('/paris/')
def meteo():
response = urlopen('https://api.openweathermap.org/data/2.5/forecast/daily?q=Paris,fr&cnt=16&appid=bd5e378503939ddaee76f12ad7a97608')
raw_content = response.read()
json_content = json.loads(raw_content.decode('utf-8'))
results = []
for list_element in json_content.get('list', []):
dt_value = list_element.get('dt')
temp_day_value = list_element.get('temp', {}).get('day') - 273.15 # Conversion de Kelvin en °c
results.append({'Jour': dt_value, 'temp': temp_day_value})
return jsonify(results=results)
@app.route("/rapport/")
def mongraphique():
return render_template("graphique.html")
@app.route("/histogramme/")
def monhistigramme():
return render_template("histogramme.html")
if __name__ == "__main__":
app.run(debug=True)