mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-18 10:18:48 +00:00
Implemented the refreshToken() method
This commit is contained in:
parent
17fcc6cc18
commit
9507bcc26c
36
actions.py
36
actions.py
@ -5,9 +5,16 @@ import datetime
|
|||||||
import dateutil
|
import dateutil
|
||||||
import os
|
import os
|
||||||
from checks import checkTimestamp
|
from checks import checkTimestamp
|
||||||
|
from checks import getToken
|
||||||
|
|
||||||
|
def clear_screen():
|
||||||
|
IS_WINDOWS = os.name == "nt"
|
||||||
|
if IS_WINDOWS:
|
||||||
|
os.system("cls")
|
||||||
|
else:
|
||||||
|
os.system("clear")
|
||||||
|
|
||||||
def refreshToken():
|
def refreshToken():
|
||||||
print("Not implemented yet")
|
|
||||||
if os.path.exists("login.json"):
|
if os.path.exists("login.json"):
|
||||||
try:
|
try:
|
||||||
with open("login.json") as json_data:
|
with open("login.json") as json_data:
|
||||||
@ -15,14 +22,35 @@ def refreshToken():
|
|||||||
saveTime = dateutil.parser.parse(login["TIMESTAMP"])
|
saveTime = dateutil.parser.parse(login["TIMESTAMP"])
|
||||||
curTime = datetime.datetime.now().replace(tzinfo=None)# TODO use UTC time?
|
curTime = datetime.datetime.now().replace(tzinfo=None)# TODO use UTC time?
|
||||||
json_data.close()
|
json_data.close()
|
||||||
|
|
||||||
|
LOGIN_DATA = {
|
||||||
|
"apikey": login["API_KEY"],
|
||||||
|
"userkey": login["USER_KEY"],
|
||||||
|
"username": login["USER_NAME"]
|
||||||
|
}
|
||||||
|
|
||||||
if checkTimestamp(saveTime, curTime):
|
if checkTimestamp(saveTime, curTime):
|
||||||
While True:
|
while True:
|
||||||
print("The current token is still valid. Do you still want to grab a different one")
|
print("Your current token is still valid. Are you sure you want to grab a different one?")
|
||||||
choice = input("(y/n) ")
|
choice = input("(y/n) ")
|
||||||
if choice is "n":
|
if choice is "n":
|
||||||
break
|
break
|
||||||
elif choice is "y":
|
elif choice is "y":
|
||||||
token = getToken() # TODO finish setting this up. Make it occur if the if statement above fails
|
login["TOKEN"] = getToken(LOGIN_DATA) # TODO find a better way to run this on both paths
|
||||||
|
login["TIMESTAMP"] = str(datetime.datetime.now().replace(tzinfo=None))
|
||||||
|
obj = open("login.json", "w")
|
||||||
|
obj.write(json.dumps(login))
|
||||||
|
obj.close()
|
||||||
|
print("\nNew token acquired!\n")
|
||||||
|
break
|
||||||
|
clear_screen()
|
||||||
|
else:
|
||||||
|
login["TOKEN"] = getToken(LOGIN_DATA)
|
||||||
|
login["TIMESTAMP"] = str(datetime.datetime.now().replace(tzinfo=None))
|
||||||
|
obj = open("login.json", "w")
|
||||||
|
obj.write(json.dumps(login))
|
||||||
|
obj.close()
|
||||||
|
print("New token acquired!\n")
|
||||||
except Exception as e:
|
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
|
print("You need to log in first. Select Login/Change login.\n") # TODO make a set of constants for error codes
|
||||||
else:
|
else:
|
||||||
|
|||||||
10
launcher.py
10
launcher.py
@ -2,13 +2,6 @@ import os # TODO: change the order of all import statements to
|
|||||||
from login import * # TODO: 2. related 3rd party
|
from login import * # TODO: 2. related 3rd party
|
||||||
from actions import * # TODO: 3. local application with blank lines between
|
from actions import * # TODO: 3. local application with blank lines between
|
||||||
|
|
||||||
def clear_screen():
|
|
||||||
IS_WINDOWS = os.name == "nt"
|
|
||||||
if IS_WINDOWS:
|
|
||||||
os.system("cls")
|
|
||||||
else:
|
|
||||||
os.system("clear")
|
|
||||||
|
|
||||||
def user_choice():
|
def user_choice():
|
||||||
return input("> ").lower().strip()
|
return input("> ").lower().strip()
|
||||||
|
|
||||||
@ -45,7 +38,8 @@ while True:
|
|||||||
login()
|
login()
|
||||||
wait()
|
wait()
|
||||||
elif choice == "4":
|
elif choice == "4":
|
||||||
refreshToken()# TODO implement this
|
clear_screen()
|
||||||
|
refreshToken()
|
||||||
wait()
|
wait()
|
||||||
elif choice == "5":
|
elif choice == "5":
|
||||||
print("install requirements")
|
print("install requirements")
|
||||||
|
|||||||
1
login.py
1
login.py
@ -52,6 +52,7 @@ def login():
|
|||||||
obj = open("login.json", "w")
|
obj = open("login.json", "w")
|
||||||
obj.write(json.dumps(login))
|
obj.write(json.dumps(login))
|
||||||
obj.close()
|
obj.close()
|
||||||
|
print("\nLogin successful!")
|
||||||
else:# if login.json already exists
|
else:# if login.json already exists
|
||||||
with open("login.json") as json_data:# TODO add a check for a login that is damaged/modified
|
with open("login.json") as json_data:# TODO add a check for a login that is damaged/modified
|
||||||
login = json.load(json_data)
|
login = json.load(json_data)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user