Files
discord-emojis/src/__main__.py

56 lines
1.3 KiB
Python
Raw Normal View History

# Copyright (c) Paillat-dev
# SPDX-License-Identifier: MIT
import pathlib
2025-05-03 16:22:11 +02:00
import sys
from download_build import dowload
from parsers import PARSERS
2025-05-03 16:22:11 +02:00
def main() -> None:
"""Download the latest discord build and extract emojis."""
build_path = pathlib.Path.cwd() / "build"
2025-05-03 16:22:11 +02:00
build_path.mkdir(exist_ok=True)
changes: bool = False
2025-05-03 16:22:11 +02:00
build_download: str = dowload()
for parser_cls in PARSERS:
parser = parser_cls(build_download)
out_path = build_path / parser.FILE_NAME
hash_path = build_path / f".{parser.FILE_NAME}.hash"
2025-05-03 16:22:11 +02:00
if not out_path.exists():
out_path.touch()
2025-05-03 16:22:11 +02:00
if hash_path.exists():
with hash_path.open("r", encoding="utf-8") as hash_file:
current_hash = hash_file.read()
else:
current_hash = ""
2025-05-03 16:22:11 +02:00
new_dump: bytes
new_hash: str
new_dump, new_hash = parser()
if current_hash == new_hash:
print(f"No changes for {parser.FILE_NAME}")
continue
2025-05-03 16:22:11 +02:00
with out_path.open("wb") as out_file:
out_file.write(new_dump)
2025-05-03 16:22:11 +02:00
with hash_path.open("w", encoding="utf-8") as hash_file:
hash_file.write(new_hash)
2025-05-03 16:22:11 +02:00
changes = True
print("Updated emojis.json")
if not changes:
sys.exit(3) # No changes
2025-05-03 16:22:11 +02:00
if __name__ == "__main__":
main()