commit fb9bff75562987eb32ce318845aea3d4a7e1e056 Author: Pascal Phelipot Date: Wed Jul 22 11:19:28 2026 +0200 initial commit diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c308432 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[project] +name = "wiki-bot" +version = "0.1.0" +description = "Bot for wiki-master" +authors = [ + {name = "Pascal Phelipot",email = "pascal@phelipot.me"} +] +requires-python = ">=3.10,<4.0" +dependencies = [ + "httpx (>=0.28.1,<0.29.0)", + "pendulum (>=3.2.0,<4.0.0)", + "sqlalchemy (>=2.0.51,<3.0.0)", + "loguru (>=0.7.3,<0.8.0)" +] + + +[build-system] +requires = ["poetry-core>=2.0.0,<3.0.0"] +build-backend = "poetry.core.masonry.api" + + diff --git a/src/__main__.py b/src/__main__.py new file mode 100644 index 0000000..7f6dfe7 --- /dev/null +++ b/src/__main__.py @@ -0,0 +1,4 @@ +import asyncio +from .app import main + +asyncio.run(main()) \ No newline at end of file diff --git a/src/app.py b/src/app.py new file mode 100644 index 0000000..2ad2a11 --- /dev/null +++ b/src/app.py @@ -0,0 +1,18 @@ +from loguru import logger +from pathlib import Path + +from .lib.utils import EveryRunRotator + +def setup(): + logs_folder = Path(__file__).parents[1].joinpath("logs") + logs_folder.mkdir(exist_ok=True) + logger.debug("log file can be found in: {}", logs_folder.as_posix()) + logger.info("Starting the bot...") + + logger.add(logs_folder.joinpath("app.log"), retention=4, rotation=EveryRunRotator()) + logger.add(logs_folder.joinpath("app.log.json"), serialize=True, rotation=EveryRunRotator(), retention=1, compression="gz") + +async def main(): + setup() + logger.info("Starting the bot...") + logger.trace("ho yeah") diff --git a/src/lib/utils.py b/src/lib/utils.py new file mode 100644 index 0000000..465ede0 --- /dev/null +++ b/src/lib/utils.py @@ -0,0 +1,13 @@ +from io import TextIOWrapper +import os + +class EveryRunRotator: + def __init__(self): + self.rotate = True + + def __call__(self, _log, log_file: TextIOWrapper): + # we do not want to rotate if the current file is empty + if self.rotate and os.stat(log_file.name).st_size != 0: + self.rotate = False + return True + return False