diff --git a/README.md b/README.md index ee4c617..9a35ed2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Como se usa? Parametros obligatorios --------------- - - -u > Usuario de timenet (Pista Cero = 4c26cc59-ee52-4c47-b7fe-1065a5e5bf84) + - -u > Usuario de timenet (Pista Cero = 4c26cc59-ee52-4c47-b7fe-1065a5e5bf84) (Lo he pasado a config.json) - -p > Pin de usuario Tendremos que escojer también entre --basedtime o --type diff --git a/autoficher.py b/autoficher.py index e532892..200b5ae 100755 --- a/autoficher.py +++ b/autoficher.py @@ -7,11 +7,7 @@ # Argumentos obligatorios: # -u USER, --user USER Usuario # -p PIN, --pin PIN Contraseña -# -t TYPE, --type TYPE Tipo marcado. 0 = Entrada, 1 = Salida -# -# Argumentos opcionales: -# -f, --festive Comprobar festivo -# -h, --help Esta ayuda +# -t TYPE, --type TYPE Tipo marcado. 0 = Entrada, 1 = Salida (Si no se utiliza -bt) # # # Creado: Omar Sánchez 04-05-2019 @@ -31,7 +27,7 @@ parser = argparse.ArgumentParser(add_help=False) parser._action_groups.pop() obligatoryArgs = parser.add_argument_group("Argumentos obligatorios") -obligatoryArgs.add_argument('-u', '--user', help="Usuario", required=True) +# obligatoryArgs.add_argument('-u', '--user', help="Usuario", 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) @@ -60,7 +56,7 @@ class AutoFicher(): exit(20) def loadConfig(self): - with open('sample.config.json', 'r') as f: + with open('config.json', 'r') as f: self.config = json.load(f) def sendReport(self, message): @@ -111,7 +107,7 @@ class AutoFicher(): typ = args.type data = { - "cp": args.user, + "cp": self.config['user'], "pin": args.pin, "typ": typ, "date": self.headers['tn-d'], @@ -123,11 +119,19 @@ class AutoFicher(): } response = self.post("check", data, self.headers) + rj = json.loads(response.text) if response.status_code != 200: - self.sendReport('Has fichado correctamente a las ' + str(datetime.strptime(self.headers["tn-d"]).strftime("%H:%M"))) + 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") + self.sendReport('Has fichado correctamente a las %s' % time) else: - self.sendReport("No se ha podido fichar, la web no ha devuelto 200 OK") + if rj['Repeated']: + time = datetime.strptime(rj['RepeatedTime'], "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=pytz.utc).astimezone( + pytz.timezone("Europe/Madrid")).strftime("%H:%M") + self.sendReport("Se ha realizado un marcaje antes a las %s" % time) + else: + self.sendReport("No se ha podido fichar, la web no ha devuelto 200 OK") if __name__ == '__main__': diff --git a/config.json b/config.json deleted file mode 100644 index e69de29..0000000 diff --git a/sample.config.json b/sample.config.json index 813acaa..05db3f5 100644 --- a/sample.config.json +++ b/sample.config.json @@ -23,5 +23,6 @@ "latitude": 0, "longitude": 0, "accuracy": 0 - } + }, + "user": "4c26cc59-ee52-4c47-b7fe-1065a5e5bf84" } \ No newline at end of file