You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

  1. import sys
  2. import json
  3. index_path = "../web/packs/index.json"
  4. try:
  5. with open(index_path) as index_file:
  6. index_data = json.load(index_file)
  7. except (FileNotFoundError, json.JSONDecodeError):
  8. index_data = {"packs": []}
  9. with open(sys.argv[-1]) as file:
  10. data = json.load(file)
  11. for pack in data["assets"]:
  12. title = pack["name"].title()
  13. if "images" not in pack["data"]:
  14. print(f"Skipping {title}")
  15. continue
  16. pack_id = f"scalar-{pack['asset_id']}"
  17. stickers = []
  18. for sticker in pack["data"]["images"]:
  19. sticker_data = sticker["content"]
  20. sticker_data["id"] = sticker_data["url"].split("/")[-1]
  21. stickers.append(sticker_data)
  22. pack_data = {
  23. "title": title,
  24. "id": pack_id,
  25. "stickers": stickers,
  26. }
  27. filename = f"scalar-{pack['name'].replace(' ', '_')}.json"
  28. pack_path = f"web/packs/{filename}"
  29. with open(pack_path, "w") as pack_file:
  30. json.dump(pack_data, pack_file)
  31. print(f"Wrote {title} to {pack_path}")
  32. if filename not in index_data["packs"]:
  33. index_data["packs"].append(filename)
  34. with open(index_path, "w") as index_file:
  35. json.dump(index_data, index_file, indent=" ")
  36. print(f"Updated {index_path}")