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.

42 lines
1.2 KiB

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