diff --git a/app.py b/app.py index 0054bd1..4a1ba81 100644 --- a/app.py +++ b/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 diff --git a/static/css/style.css b/static/css/style.css index 2eee0d5..1a016b8 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1,6 +1,25 @@ -h1 { +h1{ + color: black; +} + +form{ +} + +ul{ + +} + +li{ + +} + +.meteoAPI{ border: 2px #eee solid; - color: red; - text-align: center; padding: 10px; -} \ No newline at end of file + text-align: center; +} + +.response{ + +} + diff --git a/templates/index.html b/templates/index.html index 7d0da28..a9b8af3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,6 +6,24 @@