|
|
@@ -8,21 +8,21 @@ api_secret = os.getenv('FUDO_API_SECRET')
|
|
|
def get_token():
|
|
|
"""
|
|
|
revisa el archivo dksdabjhvjhSADhsbjksf.txt para ver si el token ya fue guardado,
|
|
|
- este contiene 3 lineas
|
|
|
- la primera es el token, la segunda es la fecha de expiracion del token. y la tercera es la fecha de creacion del token.
|
|
|
+ este contiene 2 lineas
|
|
|
+ la primera es el token y la segunda es la fecha de expiracion del token.
|
|
|
si el token no existe o ya expiro, se genera uno nuevo y se guarda en el archivo.
|
|
|
si el token existe y no ha expirado, se devuelve el token.
|
|
|
"""
|
|
|
|
|
|
- # if os.path.exists("dksdabjhvjhSADhsbjksf.txt"):
|
|
|
- # with open("dksdabjhvjhSADhsbjksf.txt", "r") as f:
|
|
|
- # lines = f.readlines()
|
|
|
- # if len(lines) == 3:
|
|
|
- # token = lines[0].strip()
|
|
|
- # expiration = lines[1].strip()
|
|
|
- # created = lines[2].strip()
|
|
|
- # if expiration - (time.time() - int(created)) < 0:
|
|
|
- # return token
|
|
|
+ if os.path.exists("dksdabjhvjhSADhsbjksf.txt"):
|
|
|
+ with open("dksdabjhvjhSADhsbjksf.txt", "r") as f:
|
|
|
+ lines = f.readlines()
|
|
|
+ if len(lines) == 2:
|
|
|
+ token = lines[0].strip()
|
|
|
+ expiration = lines[1].strip()
|
|
|
+ if int(expiration) > time():
|
|
|
+ print("Token desde cache")
|
|
|
+ return token
|
|
|
url = 'https://auth.fu.do/api'
|
|
|
data = {
|
|
|
"apiKey": api_token,
|
|
|
@@ -32,9 +32,8 @@ def get_token():
|
|
|
r = requests.post(url, data=data)
|
|
|
with open("dksdabjhvjhSADhsbjksf.txt", "w") as f:
|
|
|
f.write(r.json()['token'] + "\n")
|
|
|
- f.write(str(r.json()['expiration']) + "\n")
|
|
|
- f.write(str(time.time()) + "\n")
|
|
|
- print(r.json())
|
|
|
+ f.write(str(r.json()['exp']) + "\n")
|
|
|
+ print("Token nuevo")
|
|
|
return r.json()['token']
|
|
|
|
|
|
def get_categorys():
|