Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
feat: add option havent_paid_only, detail_log
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Dec 23, 2024
1 parent 870a351 commit 0fc3d1b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
7 changes: 6 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
},
{
"plate": "30F88251"
},
{
"plate": "30F0000000"
}
],
"notify": [
Expand All @@ -22,5 +25,7 @@
"chat_id": "-1001790012349"
}
}
]
],
"havent_paid_only": true,
"log_level": "DEBUG"
}
2 changes: 1 addition & 1 deletion schemas/config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"$defs": {"LogLevel": {"enum": ["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], "title": "LogLevel", "type": "string"}, "PlateInfo": {"properties": {"plate": {"title": "Plate", "type": "string"}, "owner": {"anyOf": [{"type": "string"}, {"type": "null"}], "default": null, "title": "Owner"}}, "required": ["plate"], "title": "PlateInfo", "type": "object"}, "Telegram": {"properties": {"bot_token": {"title": "Bot Token", "type": "string"}, "chat_id": {"title": "Chat Id", "type": "string"}}, "required": ["bot_token", "chat_id"], "title": "Telegram", "type": "object"}, "TelegramNotify": {"properties": {"telegram": {"$ref": "#/$defs/Telegram"}}, "required": ["telegram"], "title": "TelegramNotify", "type": "object"}}, "properties": {"data": {"default": [], "items": {"$ref": "#/$defs/PlateInfo"}, "title": "Data", "type": "array"}, "notify": {"default": [], "items": {"$ref": "#/$defs/TelegramNotify"}, "title": "Notify", "type": "array"}, "log_level": {"$ref": "#/$defs/LogLevel", "default": "WARNING"}}, "title": "Config", "type": "object"}
{"$defs": {"LogLevel": {"enum": ["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], "title": "LogLevel", "type": "string"}, "PlateInfo": {"properties": {"plate": {"title": "Plate", "type": "string"}, "owner": {"anyOf": [{"type": "string"}, {"type": "null"}], "default": null, "title": "Owner"}}, "required": ["plate"], "title": "PlateInfo", "type": "object"}, "Telegram": {"properties": {"bot_token": {"title": "Bot Token", "type": "string"}, "chat_id": {"title": "Chat Id", "type": "string"}}, "required": ["bot_token", "chat_id"], "title": "Telegram", "type": "object"}, "TelegramNotify": {"properties": {"telegram": {"$ref": "#/$defs/Telegram"}}, "required": ["telegram"], "title": "TelegramNotify", "type": "object"}}, "properties": {"data": {"default": [], "items": {"$ref": "#/$defs/PlateInfo"}, "title": "Data", "type": "array"}, "notify": {"default": [], "items": {"$ref": "#/$defs/TelegramNotify"}, "title": "Notify", "type": "array"}, "havent_paid_only": {"default": true, "title": "Havent Paid Only", "type": "boolean"}, "detail_log": {"default": false, "title": "Detail Log", "type": "boolean"}, "log_level": {"$ref": "#/$defs/LogLevel", "default": "WARNING"}}, "title": "Config", "type": "object"}
6 changes: 5 additions & 1 deletion src/check_phat_nguoi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from logging import Logger, getLogger

from check_phat_nguoi.modules.config_reader import config
from check_phat_nguoi.modules.logger import setup_logger

logger: Logger = getLogger(__name__)


def main() -> None:
setup_logger()
print(config)
logger.debug(config)


__all__ = ["main"]
2 changes: 2 additions & 0 deletions src/check_phat_nguoi/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Config(BaseModel):

data: list[PlateInfo] = []
notify: list[TelegramNotify] = []
havent_paid_only: bool = True
detail_log: bool = False
log_level: LogLevel = LogLevel.warning


Expand Down
6 changes: 6 additions & 0 deletions src/check_phat_nguoi/models/plate_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ class PlateInfo(BaseModel):
plate: str
owner: str | None = None

# NOTE: Dô đây lấy regex match check nha Ngẽn
r"""
if not re_match(r"^[0-9]{2}-?\w{1,2}-?\d{4,5}$", _plate):
logger.warning(f"plate {_plate} may not be valid")
"""


__all__ = ["PlateInfo"]
2 changes: 1 addition & 1 deletion src/check_phat_nguoi/modules/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from check_phat_nguoi.utils.constants import CONFIG_PATH


def _config_reader(config_path) -> Config:
def _config_reader(config_path: str) -> Config:
with open(config_path, "r", encoding="utf8") as config:
data = load(config)
return Config(**data)
Expand Down
3 changes: 2 additions & 1 deletion src/check_phat_nguoi/modules/logger.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from logging import basicConfig

from check_phat_nguoi.modules.config_reader import config
from check_phat_nguoi.utils.constants import DETAIL_LOG_MESSAGE, SIMPLE_LOG_MESSAGE


def setup_logger() -> None:
basicConfig(
level=config.log_level,
format="%(asctime)s [%(levelname)-8s] - %(message)s (%(filename)s:%(lineno)d)",
format=DETAIL_LOG_MESSAGE if config.detail_log else SIMPLE_LOG_MESSAGE,
)


Expand Down
4 changes: 4 additions & 0 deletions src/check_phat_nguoi/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
URL: str = "https://api.checkphatnguoi.vn/phatnguoi"
CONFIG_PATH: str = "config.json"
SIMPLE_LOG_MESSAGE: str = "[%(levelname)s]: %(message)s"
DETAIL_LOG_MESSAGE: str = (
"%(asctime)s [%(levelname)s] - %(message)s (%(filename)s:%(lineno)d)"
)

0 comments on commit 0fc3d1b

Please sign in to comment.