feat: upgrade to new api version

Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
Omar Sánchez Pizarro
2025-12-01 17:25:36 +01:00
parent 8123de824e
commit 1612510301
2 changed files with 34 additions and 19 deletions

View File

@@ -13,27 +13,50 @@ config = config_parser.ConfigParser().loadConfig()
class timenetManager: class timenetManager:
telegram = None telegram = None
message_acumulator = "" message_acumulator = ""
headers = {}
def __init__(self): def __init__(self):
self.telegram = telegram_bot.telegramBot() self.telegram = telegram_bot.telegramBot()
headers = { if args.pin is None:
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8", # if pin is None, prompt for it
"tn-v": "3.0.9", args.pin = int(input("Introduzca su pin: "))
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
} 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={}): def get(self, url, data={}, headers={}):
furl = config['api_url'] + url furl = config['api_url'] + url
if url != "version": if url != "version":
furl = config['api_url'] + "v1/" + url 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) return requests.get(furl, data=data, headers=headers)
def post(self, url, data={}, headers={}): def post(self, url, data={}, headers={}):
furl = config['api_url'] + url furl = config['api_url'] + url
if url != "version": if url != "version":
furl = config['api_url'] + "v1/" + url 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) 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): def addMessage(self, message):
self.message_acumulator += message + "\n" self.message_acumulator += message + "\n"
@@ -44,19 +67,17 @@ class timenetManager:
self.message_acumulator = "" self.message_acumulator = ""
def updateTime(self): 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): def updateVersion(self):
self.headers["tn-v"] = self.getVersion() self.headers["Tn-V"] = self.getVersion()
print(self.headers)
exit(20)
def getVersion(self): def getVersion(self):
self.updateTime() self.updateTime()
return self.get('version', self.headers) return self.get('version', {}, self.headers)
def getInfo(self): def getInfo(self):
return self.get('check/info', {"guid": args.user}) return self.get('check/info?guid=' + config['user'], {}, self.headers)
def sendUpdate(self): def sendUpdate(self):
conditional_response = [{ conditional_response = [{
@@ -69,10 +90,6 @@ class timenetManager:
"emoji": "🏡🏃‍♂️🏢🕐" "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 = google_calendar.GoogleCalendar()
calendar = calendar.getEvent() calendar = calendar.getEvent()
if calendar and not args.force: if calendar and not args.force:
@@ -106,17 +123,14 @@ class timenetManager:
sleep(rand) sleep(rand)
self.updateTime() self.updateTime()
data = { data = {
"cp": config['user'],
"pin": args.pin,
"typ": typ, "typ": typ,
"date": self.headers['tn-d'], "date": self.headers['tn-d'],
"geoLatitude": config['geo']['latitude'], "geoLatitude": config['geo']['latitude'],
"geoLongitude": config['geo']['longitude'], "geoLongitude": config['geo']['longitude'],
"geoError": "", "geoError": "",
"c": 1,
"geoAccuracy": config['geo']['accuracy'] "geoAccuracy": config['geo']['accuracy']
} }
response = self.post("check", data, self.headers) response = self.post("cp/checks", data, self.headers)
else: else:
self.addMessage('Corriendo en modo debug. No se realizará ninguna acción') self.addMessage('Corriendo en modo debug. No se realizará ninguna acción')
self.sendReport() self.sendReport()

View File

@@ -17,6 +17,7 @@ from app import timenet_manager
if __name__ == '__main__': if __name__ == '__main__':
af = timenet_manager.timenetManager() af = timenet_manager.timenetManager()
#print(af.getVersion().text)
af.sendUpdate() af.sendUpdate()