39 lines
997 B
Python
39 lines
997 B
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import json
|
|
import requests
|
|
|
|
|
|
def download_json_to_file(api_url, output_file):
|
|
"""
|
|
Downloads JSON data from the given API URL and saves it to the specified file.
|
|
"""
|
|
try:
|
|
response = requests.get(api_url)
|
|
response.raise_for_status() # Raise an error for bad status codes
|
|
data = response.json()
|
|
with open(output_file, 'w') as f:
|
|
json.dump(data, f, indent=4)
|
|
print(f"JSON data saved to {output_file}")
|
|
except Exception as e:
|
|
print(f"Failed to download or save JSON: {e}")
|
|
|
|
url_prefix = 'http://api.tvmaze.com/shows/<tvmazeid>'
|
|
new_updates = []
|
|
listing_file= open('./temp/filelist.txt', 'r')
|
|
|
|
|
|
os.chdir('./cache/series')
|
|
# replace with your directory path
|
|
directory_path = os.getcwd()
|
|
|
|
for line in listing_file:
|
|
seriesid = line.strip()
|
|
cachefile = f'{seriesid}.json'
|
|
download_json_to_file(url_prefix.replace('<tvmazeid>', seriesid), cachefile)
|
|
listing_file.close()
|
|
|
|
exit()
|
|
|