ajout du parametre du mode de fonctionnement

This commit is contained in:
Vincent BENOIT
2022-10-28 11:59:44 +02:00
parent f06b874e33
commit aea9abbc8b
3 changed files with 43 additions and 1410 deletions
+1 -1388
View File
File diff suppressed because one or more lines are too long
+20 -8
View File
@@ -71,12 +71,16 @@ def retreive_params():
current_app.logger.info("Récupération des paramètres de l'intercom")
current_user = get_jwt_identity()
# load data from JSON database
with open(current_app.config['DB_PATH'], 'r') as f:
data = json.load(f)
if 'PIN_ACTIF' and 'CODE_PIN' and 'NUM_AUTORISE' and 'TONE_DURATION' and 'DTMF_CODE' and 'DTMF_DURATION' in data:
content = {'pin_actif': data['PIN_ACTIF'], 'code_pin': data['CODE_PIN'], 'num_autorized': data['NUM_AUTORISE'], 'tone_duration': data['TONE_DURATION'], 'dtmf_code': data['DTMF_CODE'], 'dtmf_duration': data['DTMF_DURATION']}
else:
abort(status.HTTP_406_NOT_ACCEPTABLE, description="paramètres manquant en base de données")
try:
with open(current_app.config['DB_PATH'], 'r') as f:
data = json.load(f)
if 'OPERATION' and 'PIN_ACTIF' and 'CODE_PIN' and 'NUM_AUTORISE' and 'TONE_DURATION' and 'DTMF_CODE' and 'DTMF_DURATION' in data:
content = {'operation': data['OPERATION'], 'pin_actif': data['PIN_ACTIF'], 'code_pin': data['CODE_PIN'], 'num_autorized': data['NUM_AUTORISE'], 'tone_duration': data['TONE_DURATION'], 'dtmf_code': data['DTMF_CODE'], 'dtmf_duration': data['DTMF_DURATION']}
else:
abort(status.HTTP_406_NOT_ACCEPTABLE, description="paramètres manquant en base de données")
except FileNotFoundError as e:
current_app.logger.error("Fichier ({}) manquant".format(current_app.config['DB_PATH']))
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Fichier manquant")
return content, status.HTTP_200_OK
@@ -91,9 +95,17 @@ def update_params():
data_req = request.get_json()
current_app.logger.debug("request: {}".format(data_req))
# load data from JSON database
with open(current_app.config['DB_PATH'], 'r') as f:
data = json.load(f)
try:
with open(current_app.config['DB_PATH'], 'r') as f:
data = json.load(f)
except FileNotFoundError as e:
current_app.logger.error("Fichier ({}) manquant".format(current_app.config['DB_PATH']))
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Fichier manquant")
if 'operation' in data_req:
data['OPERATION'] = data_req['operation']
else:
abort(status.HTTP_406_NOT_ACCEPTABLE, description="paramètre manquant")
if 'pin_actif' in data_req:
data['PIN_ACTIF'] = data_req['pin_actif']
else:
+22 -14
View File
@@ -71,18 +71,22 @@ def retreive_scheduler():
current_app.logger.info("Récupération des horaires")
current_user = get_jwt_identity()
# load data from JSON database
with open(current_app.config['DB_PATH'], 'r') as f:
data = json.load(f)
content = []
if 'HORAIRES' in data:
for day in data['HORAIRES']:
h = []
for hour in data['HORAIRES'][day]:
h.append(hour)
content.append({'name': day, 'horaires':h})
#current_app.logger.debug("{}".format(content))
else:
abort(status.HTTP_406_NOT_ACCEPTABLE, description="horaire manquant en base de données")
try:
with open(current_app.config['DB_PATH'], 'r') as f:
data = json.load(f)
content = []
if 'HORAIRES' in data:
for day in data['HORAIRES']:
h = []
for hour in data['HORAIRES'][day]:
h.append(hour)
content.append({'name': day, 'horaires':h})
#current_app.logger.debug("{}".format(content))
else:
abort(status.HTTP_406_NOT_ACCEPTABLE, description="horaire manquant en base de données")
except FileNotFoundError as e:
current_app.logger.error("Fichier ({}) manquant".format(current_app.config['DB_PATH']))
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Fichier manquant")
return content, status.HTTP_200_OK
@@ -96,8 +100,12 @@ def update_scheduler():
# recuperation des attributs JSON de la requete
data_req = request.get_json()
# load data from JSON database
with open(current_app.config['DB_PATH'], 'r') as f:
data_db = json.load(f)
try:
with open(current_app.config['DB_PATH'], 'r') as f:
data_db = json.load(f)
except FileNotFoundError as e:
current_app.logger.error("Fichier ({}) manquant".format(current_app.config['DB_PATH']))
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Fichier manquant")
for day in data_db['HORAIRES']:
for d in data_req: