This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f42286a
commit 8bbfe77
Showing
14 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"$defs": {"PlateInfo": {"properties": {"plate": {"title": "Plate", "type": "string"}, "owner": {"anyOf": [{"type": "string"}, {"type": "null"}], "default": null, "title": "Owner"}}, "required": ["plate"], "title": "PlateInfo", "type": "object"}}, "properties": {"data": {"items": {"$ref": "#/$defs/PlateInfo"}, "title": "Data", "type": "array"}}, "required": ["data"], "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"}, "log_level": {"$ref": "#/$defs/LogLevel", "default": "WARNING"}}, "title": "Config", "type": "object"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
from check_phat_nguoi.modules.config_reader import config_reader | ||
from check_phat_nguoi.modules.config_reader import config | ||
from check_phat_nguoi.modules.logger import setup_logger | ||
|
||
|
||
def main(): | ||
print(config_reader("config.json")) | ||
def main() -> None: | ||
setup_logger() | ||
print(config) | ||
|
||
|
||
__all__ = ["main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
__all__ = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
from pydantic import BaseModel | ||
from pydantic import BaseModel, ConfigDict | ||
|
||
from check_phat_nguoi.models.log_level import LogLevel | ||
from check_phat_nguoi.models.notify.telegram_notify import TelegramNotify | ||
from check_phat_nguoi.models.plate_info import PlateInfo | ||
from check_phat_nguoi.models.telegram import Telegram | ||
|
||
|
||
class Config(BaseModel): | ||
model_config = ConfigDict(use_enum_values=True, validate_default=True) | ||
|
||
data: list[PlateInfo] = [] | ||
notify: list[Telegram] = [] | ||
notify: list[TelegramNotify] = [] | ||
log_level: LogLevel = LogLevel.warning | ||
|
||
|
||
__all__ = ["Config"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from enum import Enum | ||
|
||
|
||
class LogLevel(str, Enum): | ||
notset = "NOTSET" | ||
debug = "DEBUG" | ||
info = "INFO" | ||
warning = "WARNING" | ||
error = "ERROR" | ||
critical = "CRITICAL" | ||
|
||
|
||
__all__ = ["LogLevel"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from check_phat_nguoi.models.notify.telegram_notify import TelegramNotify | ||
|
||
__all__ = ["TelegramNotify"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from re import match as re_match | ||
|
||
from pydantic import BaseModel, field_validator | ||
|
||
|
||
class Telegram(BaseModel): | ||
bot_token: str | ||
chat_id: str | ||
|
||
@field_validator("bot_token", mode="after") | ||
@classmethod | ||
def validate_bot_token(cls, _bot_token: str) -> str: | ||
if not re_match(r"^[0-9]+:.+$", _bot_token): | ||
raise ValueError("Bot token is not valid") | ||
return _bot_token | ||
|
||
@field_validator("chat_id", mode="after") | ||
@classmethod | ||
def validate_chat_id(cls, _chat_id: str) -> str: | ||
if not re_match(r"^[+-]?[0-9]+$", _chat_id): | ||
raise ValueError("Bot token is not valid") | ||
return _chat_id | ||
|
||
|
||
__all__ = ["Telegram"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pydantic import BaseModel | ||
|
||
from check_phat_nguoi.models.notify.telegram import Telegram | ||
|
||
|
||
class TelegramNotify(BaseModel): | ||
telegram: Telegram | ||
|
||
|
||
__all__ = ["TelegramNotify"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ | |
class PlateInfo(BaseModel): | ||
plate: str | ||
owner: str | None = None | ||
|
||
|
||
__all__ = ["PlateInfo"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
from json import load | ||
|
||
from check_phat_nguoi.models.config import Config | ||
from check_phat_nguoi.utils.constants import CONFIG_PATH | ||
|
||
|
||
def config_reader(config_path) -> Config: | ||
def _config_reader(config_path) -> Config: | ||
with open(config_path, "r", encoding="utf8") as config: | ||
data = load(config) | ||
return Config(**data) | ||
|
||
|
||
config: Config = _config_reader(CONFIG_PATH) | ||
|
||
__all__ = ["config"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from logging import basicConfig | ||
|
||
from check_phat_nguoi.modules.config_reader import config | ||
|
||
|
||
def setup_logger() -> None: | ||
basicConfig( | ||
level=config.log_level, | ||
format="%(asctime)s [%(levelname)-8s] - %(message)s (%(filename)s:%(lineno)d)", | ||
) | ||
|
||
|
||
__all__ = ["setup_logger"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
URL: str = "https://api.checkphatnguoi.vn/phatnguoi" | ||
CONFIG_PATH: str = "config.json" |