This commit is contained in:
Yûki VACHOT 2021-10-18 08:38:41 +02:00
parent ce6ffcf1c9
commit 83892c465f
2 changed files with 57 additions and 18 deletions

55
app.py
View file

@ -27,30 +27,65 @@ def hello_world(): # put application's code here
return 'Hello World!' return 'Hello World!'
# TODO Recherche d'une ville # Recherche d'une ville
@app.route('/searchCity', methods=['POST', 'GET']) @app.route('/searchCity', methods=['POST', 'GET'])
def searchCity(): # put application's code here def searchCity(): # put application's code here
if request.method == 'POST': if request.method == 'POST':
city = request.form['search'] search = request.form['search']
else: else:
city = request.args.get('search') search = request.args.get('search')
with closing(urlopen(API_LOCATION_CITIES + API_TOKEN + METEOCONCEPT_TOKEN + API_SEARCH + city)) as f:
if METEOCONCEPT_TOKEN == -1:
log('Env variable METEOCONCEPT_TOKEN not passed')
return 'Env variable METEOCONCEPT_TOKEN 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'] cities = json.loads(f.read())['cities']
return json.dumps(cities, indent=INDENT, sort_keys=True) return json.dumps(cities, indent=INDENT, sort_keys=True)
# TODO Informations sur la Ville # Informations sur la Ville
@app.route('/city', methods=['POST', 'GET'])
def getCity(): # put application's code here
if request.method == 'POST':
insee = request.form['insee']
else:
insee = request.args.get('insee')
if METEOCONCEPT_TOKEN == -1:
log('Env variable METEOCONCEPT_TOKEN not passed')
return 'Env variable METEOCONCEPT_TOKEN not passed'
else:
log('Env variable METEOCONCEPT_TOKEN passed')
with closing(urlopen(API_LOCATION_CITY + API_TOKEN + METEOCONCEPT_TOKEN + API_INSEE + insee)) as f:
city = json.loads(f.read())['city']
return json.dumps(city, indent=INDENT, sort_keys=True)
# TODO Information sur la ville et Ephéméride # TODO Information sur la ville et Ephéméride
@app.route('/ephemeride', methods=['POST', 'GET'])
def ephemeride(): # put application's code here
if request.method == 'POST':
insee = request.form['insee']
else:
insee = request.args.get('insee')
if METEOCONCEPT_TOKEN == -1:
log('Env variable METEOCONCEPT_TOKEN not passed')
return 'Env variable METEOCONCEPT_TOKEN not passed'
else:
log('Env variable METEOCONCEPT_TOKEN passed')
with closing(urlopen(API_EPHEMERIDE + API_TOKEN + METEOCONCEPT_TOKEN + API_INSEE + insee)) as f:
cityEph = json.loads(f.read())
return json.dumps(cityEph, indent=INDENT, sort_keys=True)
# TODO Informations sur la Ville
if __name__ == '__main__': if __name__ == '__main__':
PORT = int(os.environ.get('PORT', 33507)) PORT = int(os.environ.get('PORT', 33507))
# On Linux or MAC 'export METEOCONCEPT_TOKEN=...' (check shell echo $METEOCONCEPT_TOKEN) # On Linux or MAC 'export METEOCONCEPT_TOKEN=...' (check shell echo $METEOCONCEPT_TOKEN)
# On Windows 'set METEOCONCEPT_TOKEN=...' (check on Powershell echo $Env:METEOCONCEPT_TOKEN) # On Windows 'set METEOCONCEPT_TOKEN=...' (check on Powershell echo $Env:METEOCONCEPT_TOKEN)
METEOCONCEPT_TOKEN = int(os.environ.get('METEOCONCEPT_TOKEN', -1)) METEOCONCEPT_TOKEN = int(os.environ.get('METEOCONCEPT_TOKEN', -1))
if METEOCONCEPT_TOKEN == -1:
log('Env variable METEOCONCEPT_TOKEN not passed')
sys.exit(0)
else:
log('Env variable METEOCONCEPT_TOKEN passed')
app.run(host='0.0.0.0', port=PORT, debug=True) app.run(host='0.0.0.0', port=PORT, debug=True)

View file

@ -2,12 +2,16 @@
INDENT = 4 INDENT = 4
# API URL # API URL
BASE_API_URL = 'https://api.meteo-concept.com/api/'
API_TOKEN = '?token=' API_TOKEN = '?token='
API_SEARCH = '&search=' API_SEARCH = '&search='
API_INSEE = '&insee='
API_LOCATION_CITIES = 'https://api.meteo-concept.com/api/location/cities' API_LOCATION_CITIES = BASE_API_URL + 'location/cities'
API_LOCATION_CITY = 'https://api.meteo-concept.com/api/location/city' API_LOCATION_CITY = BASE_API_URL + 'location/city'
API_EPHEMERIDE = 'https://api.meteo-concept.com/api/ephemeride/1' API_EPHEMERIDE = BASE_API_URL + 'ephemeride/1'
API_OBSERVATIONS_AROUND = BASE_API_URL + 'observations/around'
# STATIC VARIABLES # STATIC VARIABLES
WINDDIRS = [ WINDDIRS = [