diff --git a/actions.py b/actions.py index 54fee0a..8b2b56c 100644 --- a/actions.py +++ b/actions.py @@ -1,10 +1,12 @@ -import requests +import os +import subprocess import shutil import json import datetime + +import requests import dateutil -import os -import subprocess + from checks import checkTimestamp from checks import getToken @@ -78,7 +80,7 @@ def clearFolders(): # TODO implement this os.remove(delPath) print(folder + " cleared\n") else: - print(folder + " is already empty") + print("'" + folder + "'" + " is already empty") else: createFolder(folder) print("") @@ -96,10 +98,7 @@ def searchImages(idNum, keyType, authHeaders): # This is getting a list of file quit() def downloadImages(imageType, respObj, idNum): # TODO some images arent grabbed through the api. save the image number and make a try catch to get any missing images - if (os.path.exists(imageType)): # TODO add try catch here - print("\nClearing /%s/" % imageType) - shutil.rmtree(imageType) - os.makedirs(imageType) + clearFolders() parsed_respObj = json.loads(respObj.content) @@ -114,9 +113,8 @@ def download(imageType, parsed_respObj): fileName = parsed_respObj["data"][counter]["fileName"] # TODO the download method should start here, move everything else up to downloadImages counter = counter + 1 - slashIndex = fileName.rfind("/") - saveName = fileName[slashIndex + 1:] - + slashIndex = fileName.rfind("/") # This is used to slice the url at the beginning of the filename + saveName = fileName[slashIndex + 1:] # For example 'https://thetvdb.com/banners/fanart/original/32451-3.jpg' --> '32451.jpg' saveNameList.append(saveName) print("Downloading... " + fileName) diff --git a/launcher.py b/launcher.py index 8a47a6e..838d5f9 100644 --- a/launcher.py +++ b/launcher.py @@ -1,7 +1,9 @@ -import os # TODO: change the order of all import statements to 1. standard library -from login import login # TODO: 2. related 3rd party -from actions import wait # TODO: 3. local application. with blank lines between and remove wilcard symbols +import os + +from login import login +from actions import wait from actions import clear_screen +from actions import clearFolders from actions import clearLogin from actions import refreshToken from actions import update diff --git a/login.py b/login.py index 2230b72..0a36d3f 100644 --- a/login.py +++ b/login.py @@ -1,10 +1,13 @@ import json import os.path -from checks import * -from actions import * import datetime + import dateutil.parser +from actions import refreshToken +from checks import getToken + + def login(): if os.path.exists("login.json") == False: obj = open("login.json", "w") @@ -24,7 +27,7 @@ def login(): 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") + print("You can find your user key & request an API key while logged in at:\nhttps://www.thetvdb.com/?tab=userinfo\n") while tmp_api_key is "": tmp_api_key = input("Enter your api key: ") diff --git a/search.py b/search.py index 722551a..94e8aa6 100644 --- a/search.py +++ b/search.py @@ -1,7 +1,9 @@ -import requests -import json -import urllib.parse import os.path +import json + +import requests +import urllib.parse + from actions import wait