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

Commit

Permalink
feat: handle unpaid only case
Browse files Browse the repository at this point in the history
  • Loading branch information
NTGNguyen committed Jan 1, 2025
1 parent 81f6b2f commit 1a4efc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/check_phat_nguoi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
async def _main():
setup_logger()
logger.debug(config)
get_data_object = GetDataCheckPhatNguoi(_config_reader().data)
config_object = _config_reader()
get_data_object = GetDataCheckPhatNguoi(config_object.data)
data = await get_data_object.get_data()
plate_object = PlatesModel(plates=data)
message_object = Message(plate_context_object=plate_object)
message_object = Message(
plate_context_object=plate_object, config_object=config_object
)
message_dict = message_object.format_messages()
for notify_object in _config_reader().notify:
for notify_object in config_object.notify:
telegram_object = Telegram(notify_object, message_dict)
await telegram_object.send_messages()

Expand Down
10 changes: 6 additions & 4 deletions src/check_phat_nguoi/notify/message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from check_phat_nguoi.config.dto.config import ConfigDTO
from check_phat_nguoi.context import PlateInfoModel, PlatesModel
from check_phat_nguoi.context.plate_context.models.resolution_office import (
ResolutionOfficeModel,
Expand All @@ -10,8 +11,9 @@


class Message:
def __init__(self, plate_context_object: PlatesModel):
def __init__(self, plate_context_object: PlatesModel, config_object: ConfigDTO):
self._plate_context_object: PlatesModel = plate_context_object
self._config_object: ConfigDTO = config_object

@staticmethod
def format_location(
Expand All @@ -34,7 +36,7 @@ def format_location(

@staticmethod
def format_message(
plate_info_context: PlateInfoModel,
plate_info_context: PlateInfoModel, unpaid_paid_only: bool
) -> tuple[str, ...]:
return tuple(
[
Expand All @@ -51,14 +53,14 @@ def format_message(
resolution_locations=Message.format_location(vio.resolution_office),
)
for vio in plate_info_context.violation
if vio.status
if not vio.status or unpaid_paid_only
]
)

def format_messages(self) -> dict[str, tuple[str, ...]]:
message_dict: dict[str, tuple[str, ...]] = {}
for plate_info_context in self._plate_context_object.plates:
message_dict[plate_info_context.plate] = Message.format_message(
plate_info_context
plate_info_context, self._config_object.unpaid_only
)
return message_dict

0 comments on commit 1a4efc4

Please sign in to comment.