mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-16 17:38:47 +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 requests
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
|
import datetime
|
||||||
|
import dateutil
|
||||||
import os
|
import os
|
||||||
|
from checks import checkTimestamp
|
||||||
|
|
||||||
def refreshToken():
|
def refreshToken():
|
||||||
print("Not implemented yet")
|
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():
|
def clearLogin():
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -32,8 +32,8 @@ def checkStatus(response, v):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def checkTimestamp(saveTime, curTime):
|
def checkTimestamp(saveTime, curTime): # Returns true if the token is still valid
|
||||||
if curTime - saveTime < datetime.timedelta(0, 86100, 0):# if less than 23h 55m since last token grab
|
if curTime - saveTime < datetime.timedelta(0, 86100, 0):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -24,7 +24,7 @@ while True:
|
|||||||
|
|
||||||
print("1. Search theTVDB.com")
|
print("1. Search theTVDB.com")
|
||||||
print("2. Clear download folders")
|
print("2. Clear download folders")
|
||||||
print("3. Change login")
|
print("3. Login/Change login")
|
||||||
print("4. Refresh API Token")
|
print("4. Refresh API Token")
|
||||||
print("5. Install Requirements")
|
print("5. Install Requirements")
|
||||||
print("6. Check for updates\n")
|
print("6. Check for updates\n")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user