diff --git a/app/strings.py b/app/strings.py new file mode 100644 index 0000000..2e1e774 --- /dev/null +++ b/app/strings.py @@ -0,0 +1,37 @@ +tnv_string = "Tn-V" +tnd_string = "Tn-D" + +conditional_response = [{ + "text": "fichado", + "text2": "fichar", + "emoji": "πŸ•πŸ’πŸƒβ€β™‚οΈπŸ‘" +},{ + "text": "desfichado", + "text2": "desfichar", + "emoji": "πŸ‘πŸƒβ€β™‚οΈπŸ’πŸ•" +}] + +user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" +tn_u = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" + +responses = { + "check successful": "Has %s correctamente a las %s", +} + +messages = { + "waiting": "Esperando %s segundos para %s en un minuto aleatorio", + "debug": "Corriendo en modo debug. No se realizarΓ‘ ninguna acciΓ³n", + "success": "πŸŸ’πŸ• %s correctamente a las %s", +} + +errors = { + "login": "πŸŸ₯πŸ• Error al iniciar sesiΓ³n: %s", + "get_checks": "πŸŸ₯πŸ• Error al obtener los checks: %s", + "post_checks": "πŸŸ₯πŸ• Error al hacer check: %s - %s", + "no_valid_worker": "πŸŸ₯πŸ• El trabajador no ha podido ser identificado", + "check_failed": "πŸŸ₯πŸ• No se ha podido fichar, la web no ha devuelto 200 OK", + "check_already_done": "πŸŸ₯πŸ• Ya se ha realizado este marcaje antes a las %s", + "calendar_check": "πŸŸ₯πŸ• ComprobaciΓ³n de calendario: %s", + "general_error": "πŸŸ₯πŸ• Error: %s", + +} \ No newline at end of file diff --git a/app/timenet_manager.py b/app/timenet_manager.py index 2632ff5..7714ddb 100644 --- a/app/timenet_manager.py +++ b/app/timenet_manager.py @@ -9,19 +9,7 @@ from app import arg_parser, config_parser, telegram_bot, google_calendar, utils args = arg_parser.ArgParser().parse() config = config_parser.ConfigParser().loadConfig() -tnv_string = "Tn-V" -tnd_string = "Tn-D" - - -conditional_response = [{ - "text": "fichado", - "text2": "fichar", - "emoji": "πŸ•πŸ’πŸƒβ€β™‚οΈπŸ‘" -},{ - "text": "desfichado", - "text2": "desfichar", - "emoji": "πŸ‘πŸƒβ€β™‚οΈπŸ’πŸ•" -}] +from app import strings class timenetManager: telegram = None @@ -45,9 +33,9 @@ class timenetManager: "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", - tnv_string: "wcp_8.0.0.2", - "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36", - "Tn-U": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" + strings.tnv_string: "wcp_8.0.0.2", + "User-Agent": strings.user_agent, + "Tn-U": strings.tn_u } self.login() @@ -91,11 +79,11 @@ class timenetManager: def updateTime(self): now = datetime.now().astimezone(pytz.UTC) - self.headers[tnd_string] = "\"" + now.strftime("%Y-%m-%dT%H:%M:%SZ") + "\"" + self.headers[strings.tnd_string] = "\"" + now.strftime("%Y-%m-%dT%H:%M:%SZ") + "\"" self.headers["dStr"] = "\"" + now.strftime("%d/%m/%Y %H:%M:%S") + "\"" def updateVersion(self): - self.headers[tnv_string] = self.getVersion() + self.headers[strings.tnv_string] = self.getVersion() def getVersion(self): self.updateTime() @@ -113,7 +101,7 @@ class timenetManager: today_checks = json.loads(response.text) - if today_checks['C'] and today_checks['C'][0]['C'][-1]['T'] == typ: + if today_checks['C'] and today_checks['C'][0] and today_checks['C'][0]['C'] and today_checks['C'][0]['C'][-1] and today_checks['C'][0]['C'][-1]['T'] == typ: self.addMessage("Ya se ha realizado este marcaje antes a las %s" % today_checks['C'][0]['C'][-1]['H']) self.sendReport() return True @@ -156,13 +144,13 @@ class timenetManager: if not args.debug: self.addMessage("####HACIENDO CHECK####") rand = utils.numero_aleatorio_con_probabilidad(230, 0.5) - self.addMessage("Esperando %s segundos para %s en un minuto aleatorio" % (rand,conditional_response[int(typ)]["text2"])) + self.addMessage("Esperando %s segundos para %s en un minuto aleatorio" % (rand,strings.conditional_response[int(typ)]["text2"])) self.sendReport() sleep(rand) self.updateTime() data = { "typ": typ, - "date": self.headers[tnd_string], + "date": self.headers[strings.tnd_string], "geoLatitude": config['geo']['latitude'], "geoLongitude": config['geo']['longitude'], "geoError": "", @@ -193,7 +181,7 @@ class timenetManager: 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") - self.addMessage('%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' % (strings.conditional_response[int(typ)]['emoji'], strings.conditional_response[int(typ)]['text'], time)) else: self.addMessage("πŸŸ₯πŸ• No se ha podido fichar, la web no ha devuelto 200 OK")