Files
ccr_windmill/u/joshuakrzemien/mtg_json_download.py
2025-08-27 12:55:29 -04:00

34 lines
1.1 KiB
Python

import os
import wmill
import requests
# You can import any PyPi package.
# See here for more info: https://www.windmill.dev/docs/advanced/dependencies_in_python
# you can use typed resources by doing a type alias to dict
#postgresql = dict
def main():
url = "https://mtgjson.com/api/v5/TcgplayerSkus.json.zip"
files = {
"skus": "https://mtgjson.com/api/v5/TcgplayerSkus.json.zip",
"identifiers": "https://mtgjson.com/api/v5/AllIdentifiers.json.zip"
}
success = {}
for file_type, url in files.items():
response = requests.get(url)
response.raise_for_status()
file_name = url.split("/")[-1]
content_type = response.headers.get("Content-Type")
if content_type == 'application/zip':
# save file
path = f"./shared/{file_name}"
with open(path, 'wb') as f:
f.write(response.content)
success[file_name] = True
else:
success[file_name] = False
return success
# success {"TcgplayerSkus.json.zip": True, "AllIdentifiers.json.zip": True}