From 1612510301530496f164ecb814d411f984d35776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20S=C3=A1nchez=20Pizarro?= Date: Mon, 1 Dec 2025 17:25:36 +0100 Subject: [PATCH] feat: upgrade to new api version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Omar Sánchez Pizarro --- app/timenet_manager.py | 52 +++++++++++++++++++++++++++--------------- main.py | 1 + 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/app/timenet_manager.py b/app/timenet_manager.py index 27a55f3..ac5e079 100644 --- a/app/timenet_manager.py +++ b/app/timenet_manager.py @@ -13,27 +13,50 @@ config = config_parser.ConfigParser().loadConfig() class timenetManager: telegram = None message_acumulator = "" + headers = {} def __init__(self): self.telegram = telegram_bot.telegramBot() - headers = { - "Content-type": "application/x-www-form-urlencoded; charset=UTF-8", - "tn-v": "3.0.9", - "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36" - } + if args.pin is None: + # if pin is None, prompt for it + args.pin = int(input("Introduzca su pin: ")) + + self.headers = { + "Content-type": "application/x-www-form-urlencoded; charset=UTF-8", + "Tn-V": "wcp_8.0.0.2", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36" + } + self.login() + def get(self, url, data={}, headers={}): furl = config['api_url'] + url if url != "version": furl = config['api_url'] + "v1/" + url + + print("[GET] %s con headers %s y data %s" % (furl, headers, data)) return requests.get(furl, data=data, headers=headers) def post(self, url, data={}, headers={}): furl = config['api_url'] + url if url != "version": furl = config['api_url'] + "v1/" + url + + print("[POST] %s con headers %s y data %s" % (furl, headers, data)) return requests.post(furl, data=data, headers=headers) + + def login(self): + self.updateTime() + + response = self.post("cp/login/" + config['user'], { + "p": args.pin, + }, self.headers) + + if response.status_code != 200: + print("Error al iniciar sesión: %s" % response.text) + + self.headers["Token"] = response.text def addMessage(self, message): self.message_acumulator += message + "\n" @@ -44,19 +67,17 @@ class timenetManager: self.message_acumulator = "" def updateTime(self): - self.headers["tn-d"] = "\"" + datetime.now().astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + "\"" + self.headers["Tn-D"] = "\"" + datetime.now().astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + "\"" def updateVersion(self): - self.headers["tn-v"] = self.getVersion() - print(self.headers) - exit(20) + self.headers["Tn-V"] = self.getVersion() def getVersion(self): self.updateTime() - return self.get('version', self.headers) + return self.get('version', {}, self.headers) def getInfo(self): - return self.get('check/info', {"guid": args.user}) + return self.get('check/info?guid=' + config['user'], {}, self.headers) def sendUpdate(self): conditional_response = [{ @@ -69,10 +90,6 @@ class timenetManager: "emoji": "🏡🏃‍♂️🏢🕐" }] - 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 and not args.force: @@ -106,17 +123,14 @@ class timenetManager: sleep(rand) self.updateTime() data = { - "cp": config['user'], - "pin": args.pin, "typ": typ, "date": self.headers['tn-d'], "geoLatitude": config['geo']['latitude'], "geoLongitude": config['geo']['longitude'], "geoError": "", - "c": 1, "geoAccuracy": config['geo']['accuracy'] } - response = self.post("check", data, self.headers) + response = self.post("cp/checks", data, self.headers) else: self.addMessage('Corriendo en modo debug. No se realizará ninguna acción') self.sendReport() diff --git a/main.py b/main.py index 308e910..a93d2b9 100755 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ from app import timenet_manager if __name__ == '__main__': af = timenet_manager.timenetManager() + #print(af.getVersion().text) af.sendUpdate()