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:
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()

View File

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