diff --git a/autoficher.py b/autoficher.py index d9bab82..49a06c3 100755 --- a/autoficher.py +++ b/autoficher.py @@ -1,10 +1,13 @@ #!/usr/bin/env python3 # encoding: utf-8 # -# Automarcaje +# Automarcaje para timenet.gpisoftware.com +# Uso: autoficher.py +# Type: 0 marcar, 1 desmarcar # # Creado: Omar Sánchez 04-05-2019 +# Importamos librerias import os import json import sys @@ -13,37 +16,49 @@ from datetime import timedelta import requests import urllib.parse - -if len(sys.argv) <= 2: - print("No has escrito el pin ni tipo de marcaje") +# Comprobamos que todos los argumentos estan introducidos +if len(sys.argv) == 1: + print("Usuario no introducido") + sys.exit(1) +if len(sys.argv) == 2: + print("Pin no introducido") + sys.exit(1) +if len(sys.argv) == 3: + print("Tipo de marcaje no introducido") sys.exit(1) +# Definimos las variables de tiempo y argumentos date = datetime.now().strftime("%d/%m/%Y+%H:%M:%S") -calendar = (datetime.now() + timedelta(days=3)).strftime("%d/%m/%Y") -#calendar = datetime.now().strftime("%d/%m/%Y") -pin = sys.argv[1] -typ = sys.argv[2] +#calendar = (datetime.now() + timedelta(days=3)).strftime("%d/%m/%Y") +calendar = datetime.now().strftime("%d/%m/%Y") +user = sys.argv[1] +pin = sys.argv[2] +typ = sys.argv[3] +# URL de la api url = "https://timenet.gpisoftware.com/api/v1/cp/" -user = "4d805364-70d7-4608-bf2f-7bf7b3d32c04" -# Iniciamos Sesión +# Iniciamos Sesión y obtenemos el token headers = {'user': user, 'pass': pin} response = requests.get(url+'login', headers=headers) token = response.text.replace('"','') -# Obtenemos horas de marcaje +# Revisamos el dia en el calendario y comprobamos si es festivo o no headers = {'token': token} response = requests.get(url+"calendar?start="+calendar+"&end="+calendar, headers=headers) -calendar = json.loads(response.text) +dayType = json.loads(response.text)["DayTypes"][0]["dayMode"] -if calendar["DayTypes"][0]["dayMode"] != "NO_WORK": +# Si no es festivo.. +if dayType != "NO_WORK": + # Hacemos la llamada a la api para marcar o desmarcar print("Dia de curro") headers = {"Content-type": "application/x-www-form-urlencoded", "token": token} data = {"typ": typ, "date": urllib.parse.quote(date), "geoLatitude": "41.3908992", "geoLongitude": "2.154496", "geoErrors": ""} - print(data) - sys.exit(1) - response = requests.post(url+"checks", data) - print(response.text) + + response = requests.post(url+"checks", data=json.dumps(data), headers=headers) + if response.status_code != 200: + print("Error "+str(response.status_code)+" al realizar el envio: "+ response.text) + else: + print(response.text) else: print("Hoy no se trabaja") \ No newline at end of file