Update
This commit is contained in:
parent
221bc6c5ff
commit
2b14e193e7
3 changed files with 59 additions and 10 deletions
22
app.py
22
app.py
|
|
@ -14,17 +14,31 @@ def log(*args):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def getApiCity(search):
|
||||||
|
with closing(urlopen(API_LOCATION_CITIES + API_TOKEN + METEOCONCEPT_TOKEN + API_SEARCH + search)) as f:
|
||||||
|
cities = json.loads(f.read())['cities']
|
||||||
|
return cities
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/config')
|
@app.route('/config')
|
||||||
def config(): # put application's code here
|
def config(): # put application's code here
|
||||||
return str(INDENT) + str(WEATHER) + str(WINDDIRS)
|
return str(INDENT) + str(WEATHER) + str(WINDDIRS)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/', methods=['POST', 'GET'])
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
response = False
|
||||||
|
if request.method == 'POST':
|
||||||
|
search = request.form['search']
|
||||||
|
if search is None:
|
||||||
|
response = []
|
||||||
|
else:
|
||||||
|
response = getApiCity(search)
|
||||||
|
return render_template('index.html', response=response)
|
||||||
|
|
||||||
|
|
||||||
# Recherche d'une ville
|
# Recherche d'une ville
|
||||||
|
|
@ -43,9 +57,7 @@ def searchCity(): # put application's code here
|
||||||
return 'GET/POST search variable not passed'
|
return 'GET/POST search variable not passed'
|
||||||
else:
|
else:
|
||||||
log('Env variable METEOCONCEPT_TOKEN passed')
|
log('Env variable METEOCONCEPT_TOKEN passed')
|
||||||
with closing(urlopen(API_LOCATION_CITIES + API_TOKEN + METEOCONCEPT_TOKEN + API_SEARCH + search)) as f:
|
return getApiCity(search)
|
||||||
cities = json.loads(f.read())['cities']
|
|
||||||
return json.dumps(cities, indent=INDENT, sort_keys=True)
|
|
||||||
|
|
||||||
|
|
||||||
# Informations sur la Ville
|
# Informations sur la Ville
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,25 @@
|
||||||
h1 {
|
h1{
|
||||||
border: 2px #eee solid;
|
color: black;
|
||||||
color: red;
|
|
||||||
text-align: center;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form{
|
||||||
|
}
|
||||||
|
|
||||||
|
ul{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
li{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.meteoAPI{
|
||||||
|
border: 2px #eee solid;
|
||||||
|
padding: 10px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.response{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,24 @@
|
||||||
<title>Flask App</title>
|
<title>Flask App</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Welcome to Flask</h1>
|
<div class="meteoAPI">
|
||||||
|
<h1>WebServices : MétéoAPI</h1>
|
||||||
|
<form method="POST">
|
||||||
|
<label>Rechercher une ville : </label><input name="search"> <input type="submit" value="Search"></p>
|
||||||
|
</form>
|
||||||
|
<div class="response">
|
||||||
|
<br><br>
|
||||||
|
{% if response %}
|
||||||
|
<h2>Results</h2>
|
||||||
|
<ul>
|
||||||
|
{% for city in response %}
|
||||||
|
<ul>
|
||||||
|
<li>{{city}}</li>
|
||||||
|
</ul>
|
||||||
|
{%endfor%}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue