aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-09-08 14:55:30 +0300
committerTulir Asokan <tulir@maunium.net>2020-09-08 14:55:30 +0300
commit4bbd97cdbf5281713c613642c5275d0a9081d43f (patch)
tree0793ef8c54638b70ecef25449087e5542d374880
parent314f6c0ff564f955f13f4aee85b4865a960f3303 (diff)
Add script to convert Scalar sticker picker assets.json
-rw-r--r--scalar-convert.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/scalar-convert.py b/scalar-convert.py
new file mode 100644
index 0000000..da424b2
--- /dev/null
+++ b/scalar-convert.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+import sys
+import json
+
+index_path = "web/packs/index.json"
+
+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
+ id = f"scalar-{pack['asset_id']}"
+ 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,
+ "id": id,
+ "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}")
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage