now working again
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
37
app/strings.py
Normal file
37
app/strings.py
Normal file
@@ -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",
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,19 +9,7 @@ from app import arg_parser, config_parser, telegram_bot, google_calendar, utils
|
|||||||
args = arg_parser.ArgParser().parse()
|
args = arg_parser.ArgParser().parse()
|
||||||
config = config_parser.ConfigParser().loadConfig()
|
config = config_parser.ConfigParser().loadConfig()
|
||||||
|
|
||||||
tnv_string = "Tn-V"
|
from app import strings
|
||||||
tnd_string = "Tn-D"
|
|
||||||
|
|
||||||
|
|
||||||
conditional_response = [{
|
|
||||||
"text": "fichado",
|
|
||||||
"text2": "fichar",
|
|
||||||
"emoji": "🕐🏢🏃♂️🏡"
|
|
||||||
},{
|
|
||||||
"text": "desfichado",
|
|
||||||
"text2": "desfichar",
|
|
||||||
"emoji": "🏡🏃♂️🏢🕐"
|
|
||||||
}]
|
|
||||||
|
|
||||||
class timenetManager:
|
class timenetManager:
|
||||||
telegram = None
|
telegram = None
|
||||||
@@ -45,9 +33,9 @@ class timenetManager:
|
|||||||
"Sec-Fetch-Dest": "empty",
|
"Sec-Fetch-Dest": "empty",
|
||||||
"Sec-Fetch-Mode": "cors",
|
"Sec-Fetch-Mode": "cors",
|
||||||
"Sec-Fetch-Site": "same-origin",
|
"Sec-Fetch-Site": "same-origin",
|
||||||
tnv_string: "wcp_8.0.0.2",
|
strings.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",
|
"User-Agent": strings.user_agent,
|
||||||
"Tn-U": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
|
"Tn-U": strings.tn_u
|
||||||
}
|
}
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
@@ -91,11 +79,11 @@ class timenetManager:
|
|||||||
|
|
||||||
def updateTime(self):
|
def updateTime(self):
|
||||||
now = datetime.now().astimezone(pytz.UTC)
|
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") + "\""
|
self.headers["dStr"] = "\"" + now.strftime("%d/%m/%Y %H:%M:%S") + "\""
|
||||||
|
|
||||||
def updateVersion(self):
|
def updateVersion(self):
|
||||||
self.headers[tnv_string] = self.getVersion()
|
self.headers[strings.tnv_string] = self.getVersion()
|
||||||
|
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
self.updateTime()
|
self.updateTime()
|
||||||
@@ -113,7 +101,7 @@ class timenetManager:
|
|||||||
|
|
||||||
|
|
||||||
today_checks = json.loads(response.text)
|
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.addMessage("Ya se ha realizado este marcaje antes a las %s" % today_checks['C'][0]['C'][-1]['H'])
|
||||||
self.sendReport()
|
self.sendReport()
|
||||||
return True
|
return True
|
||||||
@@ -156,13 +144,13 @@ class timenetManager:
|
|||||||
if not args.debug:
|
if not args.debug:
|
||||||
self.addMessage("####HACIENDO CHECK####")
|
self.addMessage("####HACIENDO CHECK####")
|
||||||
rand = utils.numero_aleatorio_con_probabilidad(230, 0.5)
|
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()
|
self.sendReport()
|
||||||
sleep(rand)
|
sleep(rand)
|
||||||
self.updateTime()
|
self.updateTime()
|
||||||
data = {
|
data = {
|
||||||
"typ": typ,
|
"typ": typ,
|
||||||
"date": self.headers[tnd_string],
|
"date": self.headers[strings.tnd_string],
|
||||||
"geoLatitude": config['geo']['latitude'],
|
"geoLatitude": config['geo']['latitude'],
|
||||||
"geoLongitude": config['geo']['longitude'],
|
"geoLongitude": config['geo']['longitude'],
|
||||||
"geoError": "",
|
"geoError": "",
|
||||||
@@ -193,7 +181,7 @@ class timenetManager:
|
|||||||
self.addMessage("🕐 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:
|
else:
|
||||||
time = datetime.now().astimezone(pytz.timezone("Europe/Madrid")).strftime("%H:%M")
|
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:
|
else:
|
||||||
self.addMessage("🟥🕐 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")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user