Files
discord-emojis/src/__main__.py

48 lines
1.1 KiB
Python
Raw Normal View History

2025-05-03 16:22:11 +02:00
import os
import pathlib
import hashlib
import json
import sys
from typing import Any
from extract import extract_emojis_from_str
from download_build import dowload
def main() -> None:
build_path = pathlib.Path(os.getcwd()) / "build"
build_path.mkdir(exist_ok=True)
out_path = build_path / "emojis.json"
hash_path = build_path / "hash.txt"
if not out_path.exists():
out_path.touch()
if hash_path.exists():
with hash_path.open("r", encoding="utf-8") as hash_file:
current_hash = hash_file.read()
else:
current_hash = ""
new: dict[Any, Any] = extract_emojis_from_str(dowload()) # pyright: ignore[reportExplicitAny]
new_dump = json.dumps(new, indent=4, ensure_ascii=False).encode("utf-8")
new_hash = hashlib.sha256(string=new_dump).hexdigest()
if current_hash == new_hash:
print("No changes")
2025-05-03 16:52:39 +02:00
sys.exit(3) # No changes
2025-05-03 16:22:11 +02:00
with out_path.open("wb") as out_file:
out_file.write(new_dump)
with hash_path.open("w", encoding="utf-8") as hash_file:
hash_file.write(new_hash)
print("Updated emojis.json")
if __name__ == "__main__":
main()