2020-09-08 07:55:30 -04:00
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
|
2020-09-12 20:56:28 -04:00
|
|
|
index_path = "../web/packs/index.json"
|
2020-09-08 07:55:30 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
with open(index_path) as index_file:
|
|
|
|
index_data = json.load(index_file)
|
|
|
|
except (FileNotFoundError, json.JSONDecodeError):
|
|
|
|
index_data = {"packs": []}
|
|
|
|
|
|
|
|
with open(sys.argv[-1]) as file:
|
|
|
|
data = json.load(file)
|
|
|
|
|
|
|
|
for pack in data["assets"]:
|
|
|
|
title = pack["name"].title()
|
|
|
|
if "images" not in pack["data"]:
|
|
|
|
print(f"Skipping {title}")
|
|
|
|
continue
|
2020-09-12 20:56:28 -04:00
|
|
|
pack_id = f"scalar-{pack['asset_id']}"
|
2020-09-08 07:55:30 -04:00
|
|
|
stickers = []
|
|
|
|
for sticker in pack["data"]["images"]:
|
|
|
|
sticker_data = sticker["content"]
|
|
|
|
sticker_data["id"] = sticker_data["url"].split("/")[-1]
|
|
|
|
stickers.append(sticker_data)
|
|
|
|
pack_data = {
|
|
|
|
"title": title,
|
2020-09-12 20:56:28 -04:00
|
|
|
"id": pack_id,
|
2020-09-08 07:55:30 -04:00
|
|
|
"stickers": stickers,
|
|
|
|
}
|
|
|
|
filename = f"scalar-{pack['name'].replace(' ', '_')}.json"
|
|
|
|
pack_path = f"web/packs/{filename}"
|
|
|
|
with open(pack_path, "w") as pack_file:
|
|
|
|
json.dump(pack_data, pack_file)
|
|
|
|
print(f"Wrote {title} to {pack_path}")
|
|
|
|
if filename not in index_data["packs"]:
|
|
|
|
index_data["packs"].append(filename)
|
|
|
|
|
|
|
|
with open(index_path, "w") as index_file:
|
|
|
|
json.dump(index_data, index_file, indent=" ")
|
|
|
|
print(f"Updated {index_path}")
|