particionado

This commit is contained in:
Omar Sánchez Pizarro
2023-10-09 14:13:36 +02:00
parent 927c281631
commit d09c66b125
4711 changed files with 2368269 additions and 19 deletions

View File

@@ -8,6 +8,7 @@ config = config_parser.ConfigParser().loadConfig()
class timenetManager:
telegram = None
message_acumulator = ""
def __init__(self):
self.telegram = telegram_bot.telegramBot()
@@ -30,8 +31,12 @@ class timenetManager:
furl = config['api_url'] + "v1/" + url
return requests.post(furl, data=data, headers=headers)
def sendReport(self, message):
self.telegram.sendMessage(message)
def addMessage(self, message):
print(message)
self.message_acumulator += message + "\n"
def sendReport(self):
self.telegram.sendMessage(self.message_acumulator)
def updateTime(self):
self.headers["tn-d"] = "\"" + datetime.now().astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + "\""
@@ -51,10 +56,14 @@ class timenetManager:
def sendUpdate(self):
self.updateTime()
if args.pin is None:
# if pin is None, prompt for it
self.args.pin = int(input("Introduzca su pin: "))
calendar = google_calendar.GoogleCalendar()
calendar = calendar.getEvent()
if calendar:
self.sendReport("🟥🕐 Comprobación de calendario: " + calendar)
self.addMessage("🟥🕐 Comprobación de calendario: " + calendar)
return
typ = 0
@@ -70,7 +79,7 @@ class timenetManager:
elif hour in hOUT:
typ = 1
else:
self.sendReport("No se ha fichado ni desfichado ya que estamos en horario laboral, fuerze el estado con el parametro --type <0 = Entrada, 1 = Salida>")
self.addMessage("No se ha fichado ni desfichado ya que estamos en horario laboral, fuerze el estado con el parametro --type <0 = Entrada, 1 = Salida>")
else:
typ = args.type
@@ -88,27 +97,27 @@ class timenetManager:
response = None
if not args.debug:
self.sendReport("####HACIENDO CHECK####")
self.addMessage("####HACIENDO CHECK####")
response = self.post("check", data, self.headers)
else:
self.sendReport('Corriendo en modo debug. No se realizará ninguna acción')
self.addMessage('Corriendo en modo debug. No se realizará ninguna acción')
exit(20)
if response.text == "no valid worker":
self.sendReport("El trabajador no ha podido ser identificado")
self.addMessage("El trabajador no ha podido ser identificado")
exit(20)
try:
rj = json.loads(response.text)
except:
self.sendReport("La respuesta al hacer check no es correcta... algo ha pasado :/")
self.addMessage("La respuesta al hacer check no es correcta... algo ha pasado :/")
exit(20)
if response.status_code == 200:
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("🕐 Ya se ha realizado este marcaje antes a las %s" % time)
self.addMessage("🕐 Ya se ha realizado este marcaje antes a las %s" % time)
else:
time = datetime.now().astimezone(pytz.timezone("Europe/Madrid")).strftime("%H:%M")
@@ -119,6 +128,8 @@ class timenetManager:
"text": "desfichado",
"emoji": "🏡🏃‍♂️🏢🕐"
}]
self.sendReport('%s Has %s correctamente a las %s' % (conditional_response[int(typ)]['emoji'], conditional_response[int(typ)]['text'], time))
self.addMessage('%s Has %s correctamente a las %s' % (conditional_response[int(typ)]['emoji'], conditional_response[int(typ)]['text'], time))
else:
self.sendReport("🟥🕐 No se ha podido fichar, la web no ha devuelto 200 OK")
self.addMessage("🟥🕐 No se ha podido fichar, la web no ha devuelto 200 OK")
self.sendReport()