feat: upgrade to new api version
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -13,28 +13,51 @@ config = config_parser.ConfigParser().loadConfig()
|
||||
class timenetManager:
|
||||
telegram = None
|
||||
message_acumulator = ""
|
||||
headers = {}
|
||||
|
||||
def __init__(self):
|
||||
self.telegram = telegram_bot.telegramBot()
|
||||
|
||||
headers = {
|
||||
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": "3.0.9",
|
||||
"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()
|
||||
|
||||
Reference in New Issue
Block a user