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

Commit

Permalink
fix: use apis list, not allow single api
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Jan 16, 2025
1 parent 030a4df commit 0115611
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
6 changes: 3 additions & 3 deletions config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
{
"plate": "60A64685",
"owner": "dad",
"api": "checkphatnguoi.vn",
"apis": "checkphatnguoi.vn",
"type": 1
},
{
"plate": "98A56604",
"type": "car",
"api": ["csgt.vn", "checkphatnguoi.vn"]
"apis": ["csgt.vn", "checkphatnguoi.vn"]
},
{
"plate": "30F88251",
"type": 1,
"enable": false
}
],
"api": ["phatnguoi.vn", "checkphatnguoi.vn", "phatnguoi.vn", "csgt.vn"],
"apis": ["phatnguoi.vn", "checkphatnguoi.vn", "phatnguoi.vn", "csgt.vn"],
"notifications": [
{
"telegram": {
Expand Down
2 changes: 1 addition & 1 deletion src/check_phat_nguoi/config/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Config(BaseModel):
description="Danh sách các thiết lập để thông báo",
default_factory=tuple,
)
api: tuple[ApiEnum, ...] | ApiEnum = Field(
apis: tuple[ApiEnum, ...] = Field(
title="API",
description="Sử dụng API từ trang web nào. Mặc định sẽ là list các API như trong schema hiển thị và dừng khi 1 API lấy dữ liệu thành công. Có thể điền giá trị trùng để retry. Hoặc chỉ dùng 1 API",
default=(ApiEnum.phatnguoi_vn, ApiEnum.checkphatnguoi_vn),
Expand Down
18 changes: 10 additions & 8 deletions src/check_phat_nguoi/config/models/plate_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PlateInfo(BaseModel):
description="Kích hoạt",
default=True,
)
api: tuple[ApiEnum, ...] | ApiEnum | None = Field(
apis: tuple[ApiEnum, ...] | None = Field(
description='Sử dụng API từ trang web nào. Config giống "api" ở ngoài .Để trống sẽ sử dụng API define ở scope ngoài.',
title="API",
default=None,
Expand All @@ -49,7 +49,7 @@ def __hash__(self) -> int:
hash(self.plate)
+ hash(self.type)
+ hash(self.enabled)
+ hash(self.api)
+ hash(self.apis)
+ hash(self.owner)
)

Expand All @@ -65,14 +65,16 @@ def __eq__(self, other: Any):
all(
x == y
for x, y in zip(
(self.api,) if isinstance(self.api, ApiEnum) else self.api,
(other.api,)
if isinstance(other.api, ApiEnum)
else other.api,
(self.apis,)
if isinstance(self.apis, ApiEnum)
else self.apis,
(other.apis,)
if isinstance(other.apis, ApiEnum)
else other.apis,
)
)
if self.api and other.api
else (not self.api and not other.api)
if self.apis and other.apis
else (not self.apis and not other.apis)
)
)
return False
Expand Down
10 changes: 1 addition & 9 deletions src/check_phat_nguoi/get_data/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@ def __init__(self) -> None:

async def _get_data_for_plate(self, plate_info: PlateInfo) -> None:
# NOTE: The config has constraint that config.api will be at least 1 api in tuple
apis: tuple[ApiEnum, ...] = (
plate_info.api
if isinstance(plate_info.api, tuple)
else (plate_info.api,)
if plate_info.api
else config.api
if isinstance(config.api, tuple)
else (config.api,)
)
apis: tuple[ApiEnum, ...] = plate_info.apis if plate_info.apis else config.apis
engine: BaseGetDataEngine
for api in apis:
match api:
Expand Down

0 comments on commit 0115611

Please sign in to comment.