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()
|
||||
|
||||
|
||||
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.route('/config')
|
||||
def config(): # put application's code here
|
||||
return str(INDENT) + str(WEATHER) + str(WINDDIRS)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/', methods=['POST', 'GET'])
|
||||
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
|
||||
|
|
@ -43,9 +57,7 @@ def searchCity(): # put application's code here
|
|||
return 'GET/POST search variable not passed'
|
||||
else:
|
||||
log('Env variable METEOCONCEPT_TOKEN passed')
|
||||
with closing(urlopen(API_LOCATION_CITIES + API_TOKEN + METEOCONCEPT_TOKEN + API_SEARCH + search)) as f:
|
||||
cities = json.loads(f.read())['cities']
|
||||
return json.dumps(cities, indent=INDENT, sort_keys=True)
|
||||
return getApiCity(search)
|
||||
|
||||
|
||||
# Informations sur la Ville
|
||||
|
|
|
|||
|
|
@ -1,6 +1,25 @@
|
|||
h1 {
|
||||
h1{
|
||||
color: black;
|
||||
}
|
||||
|
||||
form{
|
||||
}
|
||||
|
||||
ul{
|
||||
|
||||
}
|
||||
|
||||
li{
|
||||
|
||||
}
|
||||
|
||||
.meteoAPI{
|
||||
border: 2px #eee solid;
|
||||
color: red;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
}
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.response{
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,24 @@
|
|||
<title>Flask App</title>
|
||||
</head>
|
||||
<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>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue