Remove unused functions and clean up json_downloader.py for better maintainability
This commit is contained in:
@@ -19,73 +19,6 @@ def download_json_to_file(api_url, output_file):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to download or save JSON: {e}")
|
print(f"Failed to download or save JSON: {e}")
|
||||||
|
|
||||||
def load(self, rawdata):
|
|
||||||
jdata = {}
|
|
||||||
jdata = json.loads(rawdata)
|
|
||||||
newdata = self.dump(jdata)
|
|
||||||
return (newdata)
|
|
||||||
|
|
||||||
|
|
||||||
def dump(self, rawdata):
|
|
||||||
jdata = json.dumps(rawdata, indent=4)
|
|
||||||
return (jdata)
|
|
||||||
|
|
||||||
|
|
||||||
def jconvert(self, inputdata):
|
|
||||||
outputdata = json.loads(inputdata)
|
|
||||||
return (outputdata)
|
|
||||||
|
|
||||||
|
|
||||||
def populate_cache(self, jdata, jfile):
|
|
||||||
try:
|
|
||||||
with open(jfile, 'w') as datafile:
|
|
||||||
datafile.write(jdata)
|
|
||||||
except Exception:
|
|
||||||
print('Unable to save cache file.')
|
|
||||||
else:
|
|
||||||
datafile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_json(weburl, seriesid, cachefile):
|
|
||||||
try:
|
|
||||||
webdata = get_data(weburl)
|
|
||||||
jdata = json.load(webdata)
|
|
||||||
except Exception as e:
|
|
||||||
print('Unable to get JSON data for ' + str(seriesid) + ': ' + str(e))
|
|
||||||
else:
|
|
||||||
if jdata == '[]':
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
populate_cache(jdata, cachefile)
|
|
||||||
|
|
||||||
def get_data(weburl):
|
|
||||||
try:
|
|
||||||
showresponse = requests.get(weburl)
|
|
||||||
except requests.exceptions.ConnectionError:
|
|
||||||
print('Unable to connect and get JSON data for url ' + str(weburl))
|
|
||||||
else:
|
|
||||||
return (showresponse.text)
|
|
||||||
|
|
||||||
|
|
||||||
def check_and_download(URL, series_id, cachefile):
|
|
||||||
try:
|
|
||||||
mazeurl = URL.replace('<seriesid>', str(series_id))
|
|
||||||
response = requests.get(mazeurl)
|
|
||||||
data = json.loads(response.text)
|
|
||||||
except FileNotFoundError:
|
|
||||||
# print(f'{cachefile} does not exist. Attempting to download.')
|
|
||||||
jget.fetch_json(
|
|
||||||
URL.replace('SERIESID', str(series_id)),
|
|
||||||
series_id,
|
|
||||||
cachefile
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
print(f'Unable to download {cachefile}. {e}')
|
|
||||||
else:
|
|
||||||
with open(cachefile, 'w') as f:
|
|
||||||
json.dump(data, f, indent=4)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
url_prefix = 'http://api.tvmaze.com/shows/<tvmazeid>'
|
url_prefix = 'http://api.tvmaze.com/shows/<tvmazeid>'
|
||||||
new_updates = []
|
new_updates = []
|
||||||
listing_file= open('./temp/filelist.txt', 'r')
|
listing_file= open('./temp/filelist.txt', 'r')
|
||||||
@@ -103,21 +36,3 @@ listing_file.close()
|
|||||||
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# files = [
|
|
||||||
# f for f in os.listdir(directory_path)
|
|
||||||
# if os.path.isfile(os.path.join(directory_path, f))
|
|
||||||
# ]
|
|
||||||
# for filename in files:
|
|
||||||
# with open(filename, 'r') as file:
|
|
||||||
# content = file.read()
|
|
||||||
# if 'Not Found' in content or 'Too Many Requests' in content:
|
|
||||||
# seriesid = filename.split('.')[0]
|
|
||||||
# new_updates.append(seriesid)
|
|
||||||
# listing.write(seriesid + '\n')
|
|
||||||
# listing.close()
|
|
||||||
|
|
||||||
# exit()
|
|
||||||
|
|
||||||
# import requests
|
|
||||||
# import json
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user