mirror of
https://github.com/ClaytonWWilson/Scraper-for-theTVDB.com.git
synced 2025-12-15 17:28:46 +00:00
Added some code to login and moved some code from TVDBSearch to checks
This commit is contained in:
parent
0c6305bc9e
commit
d559916c64
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.jpg
|
||||
login.json
|
||||
api info.txt
|
||||
__pycache__
|
||||
|
||||
@ -108,21 +108,6 @@ def tryMissing(missingNums, min, max, idNum, imageType):
|
||||
FAN_KEY_TYPE = "?keyType=fanart"# TODO check upper and lower bounds
|
||||
POS_KEY_TYPE = "?keyType=poster"
|
||||
BAN_KEY_TYPE = "?keyType=series"
|
||||
|
||||
url = "https://api.thetvdb.com/login"#TODO change this to LOGIN_URL
|
||||
|
||||
data = {
|
||||
"apikey": API_KEY,
|
||||
"userkey": USER_KEY,
|
||||
"username": USER_NAME
|
||||
}
|
||||
|
||||
headers = {# TODO uppercase this
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
|
||||
|
||||
token = getToken(url, data, headers)# TODO uppercase these
|
||||
|
||||
|
||||
|
||||
11
checks.py
11
checks.py
@ -1,13 +1,20 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
def getToken(data):#TODO add a timeout and try catch to all requests
|
||||
url = "https://api.thetvdb.com/login"
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
|
||||
def getToken(url, data, headers):#TODO add a timeout and try catch to all requests
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
if (checkStatus(response, True)):
|
||||
parsed_token = json.loads(response.content)
|
||||
token = parsed_token["token"]
|
||||
return token
|
||||
else:
|
||||
quit()
|
||||
return ""
|
||||
|
||||
def checkStatus(response, v):
|
||||
if (response.status_code != 200):
|
||||
|
||||
53
login.py
53
login.py
@ -1,6 +1,7 @@
|
||||
import json
|
||||
import os.path
|
||||
import checks
|
||||
from checks import *
|
||||
import time
|
||||
|
||||
def login():
|
||||
if (os.path.exists("login.json") == False):
|
||||
@ -16,28 +17,36 @@ def login():
|
||||
"TIMESTAMP": ""
|
||||
}
|
||||
|
||||
tmp_api_key = login["API_KEY"]
|
||||
tmp_user_key = login["USER_KEY"]
|
||||
tmp_user_name = login["USER_NAME"]
|
||||
|
||||
while tmp_api_key is "":
|
||||
tmp_api_key = input("Please enter your api key: ")
|
||||
while tmp_user_key is "":
|
||||
tmp_user_key = input("Please enter your user key: ")
|
||||
while tmp_user_name is "":
|
||||
tmp_user_name = input("Please enter your username: ")
|
||||
|
||||
LOGIN_DATA = {
|
||||
"apikey": tmp_api_key,
|
||||
"userkey": tmp_user_key,
|
||||
"username": tmp_user_name
|
||||
}
|
||||
|
||||
tmp_token = getToken(LOGIN_DATA)
|
||||
if tmp_token is "":
|
||||
print("Authentication failed. Please try again.")
|
||||
|
||||
with open("login.json") as json_data:
|
||||
# login = json.load(json_data)
|
||||
|
||||
tmp_api_key = login["API_KEY"]
|
||||
tmp_user_key = login["USER_KEY"]
|
||||
tmp_user_name = login["USER_NAME"]
|
||||
|
||||
while tmp_api_key is "":
|
||||
tmp_api_key = input("Please enter your api key: ")
|
||||
while tmp_user_key is "":
|
||||
tmp_user_key = input("Please enter your user key: ")
|
||||
while tmp_user_name is "":
|
||||
tmp_user_name = input("Please enter your username: ")
|
||||
|
||||
# TODO check token here
|
||||
login["API_KEY"] = tmp_api_key
|
||||
login["USER_KEY"] = tmp_user_key
|
||||
login["USER_NAME"] = tmp_user_name
|
||||
obj = open("login.json", "w")
|
||||
obj.write(json.dumps(login))
|
||||
obj.close()
|
||||
|
||||
login["API_KEY"] = tmp_api_key
|
||||
login["USER_KEY"] = tmp_user_key
|
||||
login["USER_NAME"] = tmp_user_name
|
||||
obj = open("login.json", "w")
|
||||
obj.write(json.dumps(login))
|
||||
obj.close()
|
||||
|
||||
def getCredentials():
|
||||
print()
|
||||
# TODO try to get token, if token fails, ask for login info again, if it passes save login details to login.py and save token with timestamp.
|
||||
# TODO at startup, check token for validity and remove it if it is expired
|
||||
|
||||
Loading…
Reference in New Issue
Block a user