ajout de la fonction de verification des horaires d'ouverture
This commit is contained in:
+49
-4
@@ -3,8 +3,8 @@
|
|||||||
"NUM_AUTORISE": "0607297154",
|
"NUM_AUTORISE": "0607297154",
|
||||||
"DTMF_CODE": "*",
|
"DTMF_CODE": "*",
|
||||||
"DTMF_DURATION": 1,
|
"DTMF_DURATION": 1,
|
||||||
"HORAIRES": [{
|
"HORAIRES": {
|
||||||
"monday":{
|
"Monday":{
|
||||||
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
||||||
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
|
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
|
||||||
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
|
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
|
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
|
||||||
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
||||||
},
|
},
|
||||||
"MARDI": {
|
"Tuesday": {
|
||||||
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
||||||
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
|
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
|
||||||
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
|
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
|
||||||
@@ -21,6 +21,51 @@
|
|||||||
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
|
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
|
||||||
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
|
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
|
||||||
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
||||||
|
},
|
||||||
|
"Wednesday": {
|
||||||
|
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
||||||
|
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
|
||||||
|
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
|
||||||
|
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
|
||||||
|
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
|
||||||
|
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
|
||||||
|
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
||||||
|
},
|
||||||
|
"Thursday": {
|
||||||
|
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
||||||
|
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
|
||||||
|
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
|
||||||
|
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
|
||||||
|
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
|
||||||
|
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
|
||||||
|
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
||||||
|
},
|
||||||
|
"Friday": {
|
||||||
|
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
||||||
|
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
|
||||||
|
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
|
||||||
|
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
|
||||||
|
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
|
||||||
|
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
|
||||||
|
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
||||||
|
},
|
||||||
|
"Saturday": {
|
||||||
|
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
||||||
|
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":0,"06h30":0,
|
||||||
|
"07h00":0,"07h30":0,"08h00":0,"08h30":0,"09h00":0,"09h30":0,"10h00":0,
|
||||||
|
"10h30":0,"11h00":0,"11h30":0,"12h00":0,"12h30":0,"13h00":0,"13h30":0,
|
||||||
|
"14h00":0,"14h30":0,"15h00":0,"15h30":0,"16h00":0,"16h30":0,"17h00":0,
|
||||||
|
"17h30":0,"18h00":0,"18h30":0,"19h00":0,"19h30":0,"20h00":0,"20h30":0,
|
||||||
|
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
||||||
|
},
|
||||||
|
"Sunday": {
|
||||||
|
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
|
||||||
|
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":0,"06h30":0,
|
||||||
|
"07h00":0,"07h30":0,"08h00":0,"08h30":0,"09h00":0,"09h30":0,"10h00":0,
|
||||||
|
"10h30":0,"11h00":0,"11h30":0,"12h00":0,"12h30":0,"13h00":0,"13h30":0,
|
||||||
|
"14h00":0,"14h30":0,"15h00":0,"15h30":0,"16h00":0,"16h30":0,"17h00":0,
|
||||||
|
"17h30":0,"18h00":0,"18h30":0,"19h00":0,"19h30":0,"20h00":0,"20h30":0,
|
||||||
|
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
|
||||||
}
|
}
|
||||||
}]
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-2
@@ -12,7 +12,8 @@ import sys, os, re
|
|||||||
import serial
|
import serial
|
||||||
import logging as log
|
import logging as log
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime, date
|
||||||
|
import calendar
|
||||||
import json
|
import json
|
||||||
|
|
||||||
###################################################################
|
###################################################################
|
||||||
@@ -86,7 +87,15 @@ def init_com(serObj=None, config=None, log=None):
|
|||||||
|
|
||||||
:return bool:
|
:return bool:
|
||||||
'''
|
'''
|
||||||
cmd_lst = ['AT', 'ATE1', 'AT+CMEE=2', 'AT+CPIN?', 'AT+CREG?', 'AT+CSQ', 'AT+CLTS=1', 'AT+CLIP=1', 'AT+VTD='+str(config['DTMF_DURATION'])]
|
cmd_lst = ['AT',
|
||||||
|
'ATE1',
|
||||||
|
'AT+CMEE=2',
|
||||||
|
'AT+CPIN?',
|
||||||
|
'AT+CREG?',
|
||||||
|
'AT+CSQ',
|
||||||
|
'AT+CLTS=1',
|
||||||
|
'AT+CLIP=1',
|
||||||
|
'AT+VTD='+str(config['DTMF_DURATION'])]
|
||||||
for cmd in cmd_lst:
|
for cmd in cmd_lst:
|
||||||
ret = send_at_cmd(cmd=cmd, serObj=serObj, log=log)
|
ret = send_at_cmd(cmd=cmd, serObj=serObj, log=log)
|
||||||
if not ret:
|
if not ret:
|
||||||
@@ -120,6 +129,26 @@ def verify_caller(buf="", num="", log=None):
|
|||||||
return False, phone_number
|
return False, phone_number
|
||||||
return True, phone_number
|
return True, phone_number
|
||||||
|
|
||||||
|
def verify_open_hours(conf=None, log=None):
|
||||||
|
'''
|
||||||
|
:param conf:
|
||||||
|
configuration object
|
||||||
|
|
||||||
|
:param log:
|
||||||
|
logger object
|
||||||
|
|
||||||
|
:return bool:
|
||||||
|
True if authorized, False otherwise
|
||||||
|
'''
|
||||||
|
my_date = date.today()
|
||||||
|
day = calendar.day_name[my_date.weekday()]
|
||||||
|
log.debug("Current day is {}".format(day))
|
||||||
|
log.debug("CONF {}".format(conf[day]))
|
||||||
|
now = datetime.now()
|
||||||
|
current_time = now.strftime("%Hh%M")
|
||||||
|
log.debug("current time : {}".format(current_time))
|
||||||
|
return True
|
||||||
|
|
||||||
###################################################################
|
###################################################################
|
||||||
# Corps principal du programme #
|
# Corps principal du programme #
|
||||||
|
|
||||||
@@ -154,6 +183,10 @@ def main():
|
|||||||
rtscts=False,
|
rtscts=False,
|
||||||
dsrdtr=False)
|
dsrdtr=False)
|
||||||
|
|
||||||
|
# Verify date and time
|
||||||
|
ret = verify_open_hours(conf=config['HORAIRES'], log=logger)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
if ser.isOpen():
|
if ser.isOpen():
|
||||||
logger.info("Le port de communication avec le GNSS_HAT est ouvert")
|
logger.info("Le port de communication avec le GNSS_HAT est ouvert")
|
||||||
try:
|
try:
|
||||||
@@ -174,6 +207,8 @@ def main():
|
|||||||
logger.debug("out: {}".format(out))
|
logger.debug("out: {}".format(out))
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
if out.startswith('+CLIP: '):
|
if out.startswith('+CLIP: '):
|
||||||
|
# Verify date and time
|
||||||
|
ret = verify_open_hours(conf=config['HORAIRES'], log=logger)
|
||||||
# Verify caller phone number
|
# Verify caller phone number
|
||||||
ret, phone_number = verify_caller(buf=out, num=config['NUM_AUTORISE'], log=logger)
|
ret, phone_number = verify_caller(buf=out, num=config['NUM_AUTORISE'], log=logger)
|
||||||
if not ret:
|
if not ret:
|
||||||
|
|||||||
Reference in New Issue
Block a user