mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-18 10:18:48 +00:00
Streamlining the login and token fetching process
This commit is contained in:
parent
07d3f1f960
commit
d31e4d563e
@ -65,12 +65,6 @@ def refreshToken():
|
|||||||
else:
|
else:
|
||||||
print("You need to log in first. Select Login/Change login.\n")
|
print("You need to log in first. Select Login/Change login.\n")
|
||||||
|
|
||||||
def clearLogin():
|
|
||||||
try:
|
|
||||||
os.remove("login.json")
|
|
||||||
except Exception as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def clearFolders(): # TODO implement this
|
def clearFolders(): # TODO implement this
|
||||||
folders = ["banner", "fanart", "poster"]
|
folders = ["banner", "fanart", "poster"]
|
||||||
del_count = 0
|
del_count = 0
|
||||||
|
|||||||
@ -4,7 +4,6 @@ from login import login
|
|||||||
from actions import wait
|
from actions import wait
|
||||||
from actions import clear_screen
|
from actions import clear_screen
|
||||||
from actions import clearFolders
|
from actions import clearFolders
|
||||||
from actions import clearLogin
|
|
||||||
from actions import refreshToken
|
from actions import refreshToken
|
||||||
from actions import update
|
from actions import update
|
||||||
from search import search
|
from search import search
|
||||||
@ -39,7 +38,7 @@ while True:
|
|||||||
wait()
|
wait()
|
||||||
elif choice == "3": # TODO if already logged in, ask 'are you sure?'
|
elif choice == "3": # TODO if already logged in, ask 'are you sure?'
|
||||||
clear_screen() # TODO wait to clear login and add a ctrl+c option to cancel
|
clear_screen() # TODO wait to clear login and add a ctrl+c option to cancel
|
||||||
clearLogin()
|
# clearLogin()
|
||||||
login()
|
login()
|
||||||
wait()
|
wait()
|
||||||
# elif choice == "4": # TODO need to perform this option automatically
|
# elif choice == "4": # TODO need to perform this option automatically
|
||||||
|
|||||||
12
login.py
12
login.py
@ -5,6 +5,7 @@ import datetime
|
|||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
|
||||||
from actions import refreshToken
|
from actions import refreshToken
|
||||||
|
from checks import checkTimestamp
|
||||||
from checks import getToken
|
from checks import getToken
|
||||||
|
|
||||||
|
|
||||||
@ -14,7 +15,6 @@ def login():
|
|||||||
obj.write("")
|
obj.write("")
|
||||||
obj.close()
|
obj.close()
|
||||||
|
|
||||||
if os.stat("login.json").st_size == 0:# Will only ask for credentials if the login file is empty
|
|
||||||
login = {
|
login = {
|
||||||
"API_KEY": "",
|
"API_KEY": "",
|
||||||
"USER_KEY": "",
|
"USER_KEY": "",
|
||||||
@ -56,15 +56,5 @@ def login():
|
|||||||
obj.write(json.dumps(login))
|
obj.write(json.dumps(login))
|
||||||
obj.close()
|
obj.close()
|
||||||
print("\nLogin successful!\n")
|
print("\nLogin successful!\n")
|
||||||
else:# if login.json already exists
|
|
||||||
with open("login.json") as json_data:# TODO add a check for a login file that is damaged/modified
|
|
||||||
login = json.load(json_data)
|
|
||||||
json_data.close()
|
|
||||||
saveTime = dateutil.parser.parse(login["TIMESTAMP"])
|
|
||||||
curTime = datetime.datetime.now().replace(tzinfo=None)# TODO use UTC time?
|
|
||||||
|
|
||||||
if checkTimestamp(saveTime, curTime):# token does not need refreshed
|
|
||||||
print("token is good")
|
|
||||||
else:
|
|
||||||
refreshToken()
|
|
||||||
# TODO at startup, check token for validity and remove it if it is expired
|
# TODO at startup, check token for validity and remove it if it is expired
|
||||||
|
|||||||
@ -27,8 +27,6 @@ def search():
|
|||||||
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?
|
||||||
if checkTimestamp(saveTime, curTime) == False:
|
if checkTimestamp(saveTime, curTime) == False:
|
||||||
# print("Your token has expired. Get a new one by choosing Refresh Token.")
|
|
||||||
# return None
|
|
||||||
refreshToken()
|
refreshToken()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(ex)
|
print(ex)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user