mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-15 17:28:46 +00:00
Added code to refreshToken()
This commit is contained in:
parent
2fab5ae2bd
commit
17fcc6cc18
22
actions.py
22
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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user