Files
discord-emojis/src/__main__.py
Paillat 1749dbffc7 Refactor code structure and enhance documentation in main modules
- Updated `pyproject.toml` to include configuration for `ruff` linting tool.
- Improved `download_build.py` by adding a docstring to the `dowload` function.
- Refactored `__main__.py` for clarity and consistency in path handling.
- Enhanced `extract.py` with detailed docstrings for error classes and functions.
2025-05-03 18:13:58 +02:00

50 lines
1.2 KiB
Python

# Copyright (c) Paillat-dev
# SPDX-License-Identifier: MIT
import hashlib
import json
import pathlib
import sys
from typing import Any
from download_build import dowload
from extract import extract_emojis_from_str
def main() -> None:
"""Download the latest discord build and extract emojis."""
build_path = pathlib.Path.cwd() / "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")
sys.exit(3) # No changes
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()