mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-15 17:28:46 +00:00
Implemented the 'Change login' option
This commit is contained in:
parent
f9c0a2ee40
commit
bcdcdd682e
24
actions.py
24
actions.py
@ -1,10 +1,34 @@
|
|||||||
import requests
|
import requests
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
def refreshToken():
|
def refreshToken():
|
||||||
print("Not implemented yet")
|
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):
|
def getImages(idNum, keyType, authHeaders):
|
||||||
imageUrl = "https://api.thetvdb.com/series/" + str(idNum) + "/images/query" + keyType
|
imageUrl = "https://api.thetvdb.com/series/" + str(idNum) + "/images/query" + keyType
|
||||||
response = requests.get(imageUrl, headers=authHeaders)
|
response = requests.get(imageUrl, headers=authHeaders)
|
||||||
|
|||||||
@ -24,9 +24,10 @@ def getToken(data):#TODO add a timeout and try catch to all requests
|
|||||||
def checkStatus(response, v):
|
def checkStatus(response, v):
|
||||||
if (response.status_code != 200):
|
if (response.status_code != 200):
|
||||||
if (v == True):
|
if (v == True):
|
||||||
print("An error occurred.")
|
print("\nAn error occurred.")
|
||||||
print("HTTP Code: " + str(response.status_code))
|
print("HTTP Code: " + str(response.status_code))
|
||||||
print("Response : " + str(response.content))
|
error = json.loads(response.content)
|
||||||
|
print("Response : " + error["Error"])
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|||||||
19
launcher.py
19
launcher.py
@ -1,4 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
from login import *
|
||||||
|
from actions import *
|
||||||
|
|
||||||
def clear_screen():
|
def clear_screen():
|
||||||
IS_WINDOWS = os.name == "nt"
|
IS_WINDOWS = os.name == "nt"
|
||||||
if IS_WINDOWS:
|
if IS_WINDOWS:
|
||||||
@ -9,6 +12,8 @@ def clear_screen():
|
|||||||
def user_choice():
|
def user_choice():
|
||||||
return input("> ").lower().strip()
|
return input("> ").lower().strip()
|
||||||
|
|
||||||
|
def wait():
|
||||||
|
input("Press enter to continue.")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
clear_screen()
|
clear_screen()
|
||||||
@ -30,14 +35,16 @@ while True:
|
|||||||
print("Search")
|
print("Search")
|
||||||
break
|
break
|
||||||
elif choice == "2":
|
elif choice == "2":
|
||||||
print("Clear download")
|
clearFolders()
|
||||||
break
|
wait()
|
||||||
elif choice == "3":
|
elif choice == "3":
|
||||||
print("Change login")
|
clear_screen()
|
||||||
break
|
clearLogin()
|
||||||
|
login()
|
||||||
|
wait()
|
||||||
elif choice == "4":
|
elif choice == "4":
|
||||||
print("Refresh token")
|
refreshToken()# TODO implement this
|
||||||
break
|
wait()
|
||||||
elif choice == "5":
|
elif choice == "5":
|
||||||
print("install requirements")
|
print("install requirements")
|
||||||
break
|
break
|
||||||
|
|||||||
21
login.py
21
login.py
@ -20,16 +20,18 @@ def login():
|
|||||||
"TIMESTAMP": ""
|
"TIMESTAMP": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_api_key = login["API_KEY"]
|
tmp_api_key = ""
|
||||||
tmp_user_key = login["USER_KEY"]
|
tmp_user_key = ""
|
||||||
tmp_user_name = login["USER_NAME"]
|
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 "":
|
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 "":
|
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 "":
|
while tmp_user_name is "":
|
||||||
tmp_user_name = input("Please enter your username: ")
|
tmp_user_name = input("Enter your username: ")
|
||||||
|
|
||||||
LOGIN_DATA = {
|
LOGIN_DATA = {
|
||||||
"apikey": tmp_api_key,
|
"apikey": tmp_api_key,
|
||||||
@ -40,7 +42,7 @@ def login():
|
|||||||
tmp_token = getToken(LOGIN_DATA)
|
tmp_token = getToken(LOGIN_DATA)
|
||||||
|
|
||||||
if tmp_token is "":
|
if tmp_token is "":
|
||||||
print("Authentication failed. Please try again.")
|
print("\nAuthentication failed. Please try again.")
|
||||||
else:
|
else:
|
||||||
login["API_KEY"] = tmp_api_key
|
login["API_KEY"] = tmp_api_key
|
||||||
login["USER_KEY"] = tmp_user_key
|
login["USER_KEY"] = tmp_user_key
|
||||||
@ -51,12 +53,11 @@ def login():
|
|||||||
obj.write(json.dumps(login))
|
obj.write(json.dumps(login))
|
||||||
obj.close()
|
obj.close()
|
||||||
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:
|
|
||||||
login = json.load(json_data)
|
login = json.load(json_data)
|
||||||
json_data.close()
|
json_data.close()
|
||||||
saveTime = dateutil.parser.parse(login["TIMESTAMP"])
|
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
|
if checkTimestamp(saveTime, curTime):# token does not need refreshed
|
||||||
print("token is good")
|
print("token is good")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user