-argumentos + ayuda
This commit is contained in:
@@ -2,8 +2,17 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
#
|
#
|
||||||
# Automarcaje para timenet.gpisoftware.com
|
# Automarcaje para timenet.gpisoftware.com
|
||||||
# Uso: autoficher.py <user> <pin> <type>
|
# usage: autoficher.py -u USER -p PIN -t TYPE [-f] [-h]
|
||||||
# Type: 0 marcar, 1 desmarcar
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
#
|
#
|
||||||
# Creado: Omar Sánchez 04-05-2019
|
# Creado: Omar Sánchez 04-05-2019
|
||||||
|
|
||||||
@@ -15,50 +24,80 @@ from datetime import datetime
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import requests
|
import requests
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
# Introducimos los argumentos obligatorios y opcionales
|
||||||
|
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('-p', '--pin', help="Contraseña", required=True)
|
||||||
|
obligatoryArgs.add_argument('-t', '--type', help="Tipo marcado. 0 = Entrada, 1 = Salida", required=True)
|
||||||
|
|
||||||
|
optionalArgs = parser.add_argument_group("Argumentos opcionales")
|
||||||
|
optionalArgs.add_argument('-f', '--festive', action="store_false", help="Comprobar festivo")
|
||||||
|
optionalArgs.add_argument('-h', '--help', action="help", help="Esta ayuda")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Comprobamos que todos los argumentos estan introducidos
|
# Comprobamos que todos los argumentos estan introducidos
|
||||||
if len(sys.argv) == 1:
|
if not args.user:
|
||||||
print("Usuario no introducido")
|
print("Usuario no introducido")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if len(sys.argv) == 2:
|
if not args.pin:
|
||||||
print("Pin no introducido")
|
print("Pin no introducido")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if len(sys.argv) == 3:
|
if not args.type:
|
||||||
print("Tipo de marcaje no introducido")
|
print("Tipo de marcaje no introducido")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Definimos las variables de tiempo y argumentos
|
class AutoFicher():
|
||||||
|
# URL de la api
|
||||||
|
url = "https://timenet.gpisoftware.com/api/v1/cp/"
|
||||||
|
# Definimos las variables de tiempo
|
||||||
date = datetime.now().strftime("%d/%m/%Y+%H:%M:%S")
|
date = datetime.now().strftime("%d/%m/%Y+%H:%M:%S")
|
||||||
#calendar = (datetime.now() + timedelta(days=3)).strftime("%d/%m/%Y")
|
#calendar = (datetime.now() + timedelta(days=3)).strftime("%d/%m/%Y")
|
||||||
calendar = datetime.now().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
|
token = ""
|
||||||
url = "https://timenet.gpisoftware.com/api/v1/cp/"
|
|
||||||
|
|
||||||
|
def __init__(self, task = ''):
|
||||||
# Iniciamos Sesión y obtenemos el token
|
# Iniciamos Sesión y obtenemos el token
|
||||||
headers = {'user': user, 'pass': pin}
|
headers = {'user': args.user, 'pass': args.pin}
|
||||||
response = requests.get(url+'login', headers=headers)
|
response = requests.get(self.url+'login', headers=headers)
|
||||||
token = response.text.replace('"','')
|
self.token = response.text.replace('"','')
|
||||||
|
|
||||||
|
def isFestive(self):
|
||||||
|
# Comprobamos si esta habilitado el comprobar festivo (Por defecto es True)
|
||||||
|
if args.festive:
|
||||||
# Revisamos el dia en el calendario y comprobamos si es festivo o no
|
# Revisamos el dia en el calendario y comprobamos si es festivo o no
|
||||||
headers = {'token': token}
|
headers = {'token': self.token}
|
||||||
response = requests.get(url+"calendar?start="+calendar+"&end="+calendar, headers=headers)
|
response = requests.get(self.url+"calendar?start="+self.calendar+"&end="+self.calendar, headers=headers)
|
||||||
dayType = json.loads(response.text)["DayTypes"][0]["dayMode"]
|
dayType = json.loads(response.text)["DayTypes"][0]["dayMode"]
|
||||||
|
|
||||||
|
if dayType == "NO_WORK":
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def sendUpdate(self):
|
||||||
# Si no es festivo..
|
# Si no es festivo..
|
||||||
if dayType != "NO_WORK":
|
if not self.isFestive():
|
||||||
# Hacemos la llamada a la api para marcar o desmarcar
|
# Hacemos la llamada a la api para marcar o desmarcar
|
||||||
print("Dia de curro")
|
print("Dia de curro")
|
||||||
headers = {"Content-type": "application/x-www-form-urlencoded", "token": token}
|
headers = {"Content-type": "application/x-www-form-urlencoded", "token": self.token}
|
||||||
data = {"typ": typ, "date": urllib.parse.quote(date), "geoLatitude": "41.3908992", "geoLongitude": "2.154496", "geoErrors": ""}
|
data = {"typ": args.type, "date": urllib.parse.quote(self.date), "geoLatitude": "41.3908992", "geoLongitude": "2.154496", "geoErrors": ""}
|
||||||
|
|
||||||
response = requests.post(url+"checks", data=json.dumps(data), headers=headers)
|
response = requests.post(self.url+"checks", data=json.dumps(data), headers=headers)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print("Error "+str(response.status_code)+" al realizar el envio: "+ response.text)
|
print("Error "+str(response.status_code)+" al realizar el envio: "+ response.text)
|
||||||
else:
|
else:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
else:
|
else:
|
||||||
print("Hoy no se trabaja")
|
print("Hoy no se trabaja")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
AutoFicher().sendUpdate()
|
||||||
Reference in New Issue
Block a user