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
f0b895b
commit 040fee2
Showing
16 changed files
with
218 additions
and
74 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
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 |
---|---|---|
|
@@ -5,6 +5,5 @@ | |
"config", | ||
"ConfigDTO", | ||
"PlateInfoDTO", | ||
"LogLevelDTO", | ||
"TelegramNotifyDTO", | ||
] |
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,6 +1,11 @@ | ||
from .api import ApiEnum | ||
from .config import ConfigDTO | ||
from .log_level import LogLevelDTO | ||
from .notify import * | ||
from .plate_info import PlateInfoDTO | ||
|
||
__all__ = ["ConfigDTO", "PlateInfoDTO", "LogLevelDTO", "TelegramNotifyDTO"] | ||
__all__ = [ | ||
"ConfigDTO", | ||
"PlateInfoDTO", | ||
"TelegramNotifyDTO", | ||
"ApiEnum", | ||
] |
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,9 @@ | ||
from enum import Enum | ||
|
||
|
||
class ApiEnum(str, Enum): | ||
checkphatnguoi_vn = "checkphatnguoi.vn" | ||
csgt_vn = "csgt.vn" | ||
|
||
|
||
__all__ = ["ApiEnum"] |
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,27 +1,47 @@ | ||
from pydantic import BaseModel, ConfigDict, Field | ||
from typing import Self | ||
|
||
from .log_level import LogLevelDTO | ||
from pydantic import BaseModel, ConfigDict, Field, model_validator | ||
|
||
from check_phat_nguoi.enums import LogLevelEnum | ||
|
||
from .api import ApiEnum | ||
from .notify.telegram_notify import TelegramNotifyDTO | ||
from .plate_info import PlateInfoDTO | ||
|
||
|
||
class ConfigDTO(BaseModel): | ||
model_config = ConfigDict(use_enum_values=True, validate_default=True) | ||
|
||
data: tuple[PlateInfoDTO, ...] = Field( | ||
plates: tuple[PlateInfoDTO, ...] = Field( | ||
description="Danh sách các biển xe", default_factory=tuple | ||
) | ||
notifications: tuple[TelegramNotifyDTO, ...] = Field( | ||
description="Danh sách các thiết lập để thông báo", default_factory=tuple | ||
) | ||
api: ApiEnum = Field( | ||
description="Sử dụng API từ trang web nào (mặc định sử dụng API từ trang checkphatnguoi.vn)", | ||
title="API", | ||
default=ApiEnum.checkphatnguoi_vn, | ||
) | ||
unpaid_only: bool = Field( | ||
description="Chỉ hiển thị thông tin vi phạm chưa nộp phạt", default=True | ||
) | ||
verbose: bool = Field( | ||
description="Hiển thị tất cả thông tin có thể hiển thị", default=False | ||
) | ||
detail_log: bool = True | ||
log_level: LogLevelDTO = LogLevelDTO.info | ||
log_level: LogLevelEnum = LogLevelEnum.info | ||
|
||
@model_validator(mode="after") | ||
def validate_type(self) -> Self: | ||
for plate in self.plates: | ||
if plate.api is None: | ||
if self.api not in (ApiEnum.checkphatnguoi_vn,): | ||
raise ValueError( | ||
f'Plate {plate}: API other than "checkphatnguoi_vn" must set "type"' | ||
) | ||
plate.api = self.api | ||
return self | ||
|
||
|
||
__all__ = ["ConfigDTO"] |
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
3 changes: 3 additions & 0 deletions
3
src/check_phat_nguoi/context/plate_context/models/plate_info.py
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .log_level import LogLevelEnum | ||
from .vehicle_type import VehicleTypeEnum | ||
|
||
__all__ = ["VehicleTypeEnum", "LogLevelEnum"] |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from enum import IntEnum | ||
|
||
|
||
class VehicleTypeEnum(IntEnum): | ||
car = 1 | ||
motorbike = 2 | ||
electric_motorbike = 3 | ||
|
||
|
||
__all__ = ["VehicleTypeEnum"] |
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,3 +1,3 @@ | ||
from .check_phat_nguoi import * | ||
from .get_data import GetData | ||
|
||
__all__ = ["GetDataCheckPhatNguoi"] | ||
__all__ = ["GetData"] |
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,22 @@ | ||
from abc import abstractmethod | ||
from typing import Self | ||
|
||
from aiohttp import ClientSession | ||
|
||
from check_phat_nguoi.config import PlateInfoDTO | ||
from check_phat_nguoi.context import PlateInfoModel | ||
|
||
|
||
class GetDataEngineBase: | ||
def __init__(self) -> None: | ||
self.session: ClientSession = ClientSession() | ||
|
||
async def __aenter__(self) -> Self: | ||
return self | ||
|
||
@abstractmethod | ||
async def __aexit__(self, exc_type, exc_value, exc_traceback) -> None: | ||
await self.session.close() | ||
|
||
@abstractmethod | ||
async def get_data(self, plate: PlateInfoDTO) -> PlateInfoModel | None: ... |
Oops, something went wrong.