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.

56 lines
2.0 KiB

  1. # maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
  2. # Copyright (C) 2020 Tulir Asokan
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. import sys
  17. import json
  18. index_path = "../web/packs/index.json"
  19. try:
  20. with open(index_path) as index_file:
  21. index_data = json.load(index_file)
  22. except (FileNotFoundError, json.JSONDecodeError):
  23. index_data = {"packs": []}
  24. with open(sys.argv[-1]) as file:
  25. data = json.load(file)
  26. for pack in data["assets"]:
  27. title = pack["name"].title()
  28. if "images" not in pack["data"]:
  29. print(f"Skipping {title}")
  30. continue
  31. pack_id = f"scalar-{pack['asset_id']}"
  32. stickers = []
  33. for sticker in pack["data"]["images"]:
  34. sticker_data = sticker["content"]
  35. sticker_data["id"] = sticker_data["url"].split("/")[-1]
  36. stickers.append(sticker_data)
  37. pack_data = {
  38. "title": title,
  39. "id": pack_id,
  40. "stickers": stickers,
  41. }
  42. filename = f"scalar-{pack['name'].replace(' ', '_')}.json"
  43. pack_path = f"web/packs/{filename}"
  44. with open(pack_path, "w") as pack_file:
  45. json.dump(pack_data, pack_file)
  46. print(f"Wrote {title} to {pack_path}")
  47. if filename not in index_data["packs"]:
  48. index_data["packs"].append(filename)
  49. with open(index_path, "w") as index_file:
  50. json.dump(index_data, index_file, indent=" ")
  51. print(f"Updated {index_path}")