Implemented the 'Change login' option

This commit is contained in:
Clayton Wilson 2017-11-02 11:50:57 -04:00
parent f9c0a2ee40
commit bcdcdd682e
4 changed files with 51 additions and 18 deletions

View File

@ -1,10 +1,34 @@
import requests
import shutil
import json
import os
def refreshToken():
print("Not implemented yet")
def clearLogin():
try:
os.remove("login.json")
except Exception as e:
pass
def clearFolders():# TODO implement this
if os.path.exists("banner"):
print("cleared")
else:
print("empty")
if os.path.exists("fanart"):
print("cleared")
else:
print("empty")
if os.path.exists("poster"):
print("cleared")
else:
print("empty")
def getImages(idNum, keyType, authHeaders):
imageUrl = "https://api.thetvdb.com/series/" + str(idNum) + "/images/query" + keyType
response = requests.get(imageUrl, headers=authHeaders)

View File

@ -24,9 +24,10 @@ def getToken(data):#TODO add a timeout and try catch to all requests
def checkStatus(response, v):
if (response.status_code != 200):
if (v == True):
print("An error occurred.")
print("\nAn error occurred.")
print("HTTP Code: " + str(response.status_code))
print("Response : " + str(response.content))
error = json.loads(response.content)
print("Response : " + error["Error"])
return False
else:
return True

View File

@ -1,4 +1,7 @@
import os
from login import *
from actions import *
def clear_screen():
IS_WINDOWS = os.name == "nt"
if IS_WINDOWS:
@ -9,6 +12,8 @@ def clear_screen():
def user_choice():
return input("> ").lower().strip()
def wait():
input("Press enter to continue.")
while True:
clear_screen()
@ -30,14 +35,16 @@ while True:
print("Search")
break
elif choice == "2":
print("Clear download")
break
clearFolders()
wait()
elif choice == "3":
print("Change login")
break
clear_screen()
clearLogin()
login()
wait()
elif choice == "4":
print("Refresh token")
break
refreshToken()# TODO implement this
wait()
elif choice == "5":
print("install requirements")
break

View File

@ -20,16 +20,18 @@ def login():
"TIMESTAMP": ""
}
tmp_api_key = login["API_KEY"]
tmp_user_key = login["USER_KEY"]
tmp_user_name = login["USER_NAME"]
tmp_api_key = ""
tmp_user_key = ""
tmp_user_name = ""
print("You can find your user key & request an API key while logged in at:\nhttps://www.thetvdb.com/?tab=userinfo")
while tmp_api_key is "":
tmp_api_key = input("Please enter your api key: ")
tmp_api_key = input("Enter your api key: ")
while tmp_user_key is "":
tmp_user_key = input("Please enter your user key: ")
tmp_user_key = input("Enter your user key: ")
while tmp_user_name is "":
tmp_user_name = input("Please enter your username: ")
tmp_user_name = input("Enter your username: ")
LOGIN_DATA = {
"apikey": tmp_api_key,
@ -40,7 +42,7 @@ def login():
tmp_token = getToken(LOGIN_DATA)
if tmp_token is "":
print("Authentication failed. Please try again.")
print("\nAuthentication failed. Please try again.")
else:
login["API_KEY"] = tmp_api_key
login["USER_KEY"] = tmp_user_key
@ -51,12 +53,11 @@ def login():
obj.write(json.dumps(login))
obj.close()
else:# if login.json already exists
with open("login.json") as json_data:
with open("login.json") as json_data:# TODO add a check for a login 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)
curTime = datetime.datetime.now().replace(tzinfo=None)# TODO use UTC time?
if checkTimestamp(saveTime, curTime):# token does not need refreshed
print("token is good")