diff --git a/actions.py b/actions.py index ad92066..662a3a9 100644 --- a/actions.py +++ b/actions.py @@ -1,10 +1,32 @@ import requests import shutil import json +import datetime +import dateutil import os +from checks import checkTimestamp def refreshToken(): print("Not implemented yet") + if os.path.exists("login.json"): + try: + with open("login.json") as json_data: + login = json.load(json_data) + saveTime = dateutil.parser.parse(login["TIMESTAMP"]) + curTime = datetime.datetime.now().replace(tzinfo=None)# TODO use UTC time? + json_data.close() + if checkTimestamp(saveTime, curTime): + While True: + print("The current token is still valid. Do you still want to grab a different one") + choice = input("(y/n) ") + if choice is "n": + break + elif choice is "y": + token = getToken() # TODO finish setting this up. Make it occur if the if statement above fails + except Exception as e: + print("You need to log in first. Select Login/Change login.\n") # TODO make a set of constants for error codes + else: + print("You need to log in first. Select Login/Change login.\n") def clearLogin(): try: diff --git a/checks.py b/checks.py index fccf1ab..9c8e6db 100644 --- a/checks.py +++ b/checks.py @@ -32,8 +32,8 @@ def checkStatus(response, v): else: return True -def checkTimestamp(saveTime, curTime): - if curTime - saveTime < datetime.timedelta(0, 86100, 0):# if less than 23h 55m since last token grab +def checkTimestamp(saveTime, curTime): # Returns true if the token is still valid + if curTime - saveTime < datetime.timedelta(0, 86100, 0): return True else: return False diff --git a/launcher.py b/launcher.py index a76a671..01b8a62 100644 --- a/launcher.py +++ b/launcher.py @@ -24,7 +24,7 @@ while True: print("1. Search theTVDB.com") print("2. Clear download folders") - print("3. Change login") + print("3. Login/Change login") print("4. Refresh API Token") print("5. Install Requirements") print("6. Check for updates\n")