config replacement form arguments
This commit is contained in:
@@ -27,7 +27,6 @@ parser = argparse.ArgumentParser(add_help=False)
|
|||||||
parser._action_groups.pop()
|
parser._action_groups.pop()
|
||||||
|
|
||||||
obligatoryArgs = parser.add_argument_group("Argumentos obligatorios")
|
obligatoryArgs = parser.add_argument_group("Argumentos obligatorios")
|
||||||
# obligatoryArgs.add_argument('-u', '--user', help="Usuario", required=True)
|
|
||||||
obligatoryArgs.add_argument('-p', '--pin', help="Contraseña", type=int, required=True)
|
obligatoryArgs.add_argument('-p', '--pin', help="Contraseña", type=int, required=True)
|
||||||
obligatoryArgs.add_argument('-t', '--type', help="Tipo marcado. 0 = Entrada, 1 = Salida", type=int)
|
obligatoryArgs.add_argument('-t', '--type', help="Tipo marcado. 0 = Entrada, 1 = Salida", type=int)
|
||||||
|
|
||||||
@@ -35,6 +34,12 @@ optionalArgs = parser.add_argument_group("Argumentos opcionales")
|
|||||||
optionalArgs.add_argument('-bt', '--basedtime', help="Hacer check o descheck según la hora del dia",
|
optionalArgs.add_argument('-bt', '--basedtime', help="Hacer check o descheck según la hora del dia",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
optionalArgs.add_argument('-h', '--help', action="help", help="Esta ayuda")
|
optionalArgs.add_argument('-h', '--help', action="help", help="Esta ayuda")
|
||||||
|
optionalArgs.add_argument('-d', '--debug', action='store_true')
|
||||||
|
|
||||||
|
optionalArgs.add_argument('-c', '--config', help="Rúta al archivo de configuración")
|
||||||
|
optionalArgs.add_argument('-u', '--user', help="Usuario")
|
||||||
|
optionalArgs.add_argument('-glo', '--geoLongitude', help="Longitud")
|
||||||
|
optionalArgs.add_argument('-gla', '--geoLatitude', help="Latitud")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -56,9 +61,23 @@ class AutoFicher():
|
|||||||
exit(20)
|
exit(20)
|
||||||
|
|
||||||
def loadConfig(self):
|
def loadConfig(self):
|
||||||
with open('config.json', 'r') as f:
|
path = 'config.json'
|
||||||
|
|
||||||
|
if args.config:
|
||||||
|
path = args.config
|
||||||
|
|
||||||
|
with open(path, 'r') as f:
|
||||||
self.config = json.load(f)
|
self.config = json.load(f)
|
||||||
|
|
||||||
|
if args.geoLatitude:
|
||||||
|
self.config['geo']['latitude'] = args.geoLatitude
|
||||||
|
if args.geoLongitude:
|
||||||
|
self.config['geo']['longitude'] = args.geoLongitude
|
||||||
|
if args.user:
|
||||||
|
self.config['user'] = args.user
|
||||||
|
|
||||||
|
print(self.config)
|
||||||
|
|
||||||
def sendReport(self, message):
|
def sendReport(self, message):
|
||||||
bot = telegram.Bot(token=self.config['telegram']['token'])
|
bot = telegram.Bot(token=self.config['telegram']['token'])
|
||||||
bot.sendMessage(chat_id=self.config['telegram']['chat_id'], text=str(message))
|
bot.sendMessage(chat_id=self.config['telegram']['chat_id'], text=str(message))
|
||||||
@@ -118,18 +137,32 @@ class AutoFicher():
|
|||||||
"geoAccuracy": self.config['geo']['accuracy']
|
"geoAccuracy": self.config['geo']['accuracy']
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.post("check", data, self.headers)
|
response = None
|
||||||
rj = json.loads(response.text)
|
if not args.debug:
|
||||||
|
print("####HACIENDO CHECK####")
|
||||||
|
##response = self.post("check", data, self.headers)
|
||||||
|
|
||||||
|
try:
|
||||||
|
rj = json.loads(response.text)
|
||||||
|
except:
|
||||||
|
print("La respuesta al hacer check no es correcta... algo ha pasado :/")
|
||||||
|
exit(20)
|
||||||
|
|
||||||
|
if args.debug:
|
||||||
|
self.sendReport('Corriendo en modo debug. No se realizará ninguna acción')
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
if rj['Repeated']:
|
if rj['Repeated']:
|
||||||
time = datetime.strptime(rj['RepeatedTime'], "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=pytz.utc).astimezone(
|
time = datetime.strptime(rj['RepeatedTime'], "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=pytz.utc).astimezone(
|
||||||
pytz.timezone("Europe/Madrid")).strftime("%H:%M")
|
pytz.timezone("Europe/Madrid")).strftime("%H:%M")
|
||||||
self.sendReport("Se ha realizado un marcaje antes a las %s" % time)
|
self.sendReport("Se ha realizado un marcaje antes a las %s" % time)
|
||||||
else:
|
else:
|
||||||
time = datetime.strptime(self.headers["tn-d"], "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Europe/Madrid")).strftime("%H:%M")
|
time = datetime.strptime(self.headers["tn-d"], "'%Y-%m-%dT%H:%M:%SZ'").replace(
|
||||||
self.sendReport('Has fichado correctamente a las %s' % time)
|
tzinfo=pytz.utc).astimezone(pytz.timezone("Europe/Madrid")).strftime("%H:%M")
|
||||||
|
|
||||||
|
rtext = 'fichado'
|
||||||
|
if typ:
|
||||||
|
rtext = 'desfichado'
|
||||||
|
self.sendReport('Has %s correctamente a las %s' % (rtext, time))
|
||||||
else:
|
else:
|
||||||
self.sendReport("No se ha podido fichar, la web no ha devuelto 200 OK")
|
self.sendReport("No se ha podido fichar, la web no ha devuelto 200 OK")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user