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

Commit

Permalink
Merge branch 'main' into feat/print-console
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Jan 14, 2025
2 parents c686068 + 9f35541 commit 0acd960
Show file tree
Hide file tree
Showing 23 changed files with 189 additions and 180 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
branches: [main]
paths:
- docs/**
- config.sample.json
- jsfh-conf.yaml
- mkdocs.yml
- schemas/**
- config.sample.json
- requests/**
workflow_dispatch:

permissions:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Check phạt nguội

Tool kiểm tra phạt nguội cho phương tiện giao thông của bạn. Hỗ trợ notify đến các nền tảng Telegram,...
Tool kiểm tra phạt nguội cho phương tiện giao thông của bạn. Hỗ trợ notify đến các nền tảng Telegram, Discord...
File renamed without changes.
41 changes: 25 additions & 16 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
# yaml-language-server: $schema=https://squidfunk.github.io/mkdocs-material/schema.json

site_name: Check Phạt Nguội
site_name: 'Check Phạt Nguội'
site_author: 'NTGNguyen & Kevin Nitro'
site_description: 'Tool kiểm tra phạt nguội'
site_url: 'https://ntgnguyen.github.io/check-phat-nguoi'
repo_url: 'https://github.com/ntgnguyen/check-phat-nguoi'
strict: true

nav:
- 'Trang chủ': index.md
- 'Sử dụng':
- usage/index.md
- usage/schedule-run.md
- 'Config schema': 'https://ntgnguyen.github.io/check-phat-nguoi/schemas/config.html'
- 'Development':
- dev/setup.md
- dev/csgt_vn.md
- dev/checkphatnguoi_vn.md
- dev/phatnguoi_vn.md
- 'Khác':
- other/references.md
- other/disclaimer.md

theme:
language: vi
icon:
Expand Down Expand Up @@ -69,21 +88,11 @@ plugins:
- stopWordFilter
- trimmer

nav:
- 'Trang chủ':
- index.md
- 'Sử dụng':
- usage/usage.md
- usage/schedule-run.md
- 'Config schema': 'https://ntgnguyen.github.io/check-phat-nguoi/schemas/config.html'
- 'Development':
- dev/setup.md
- dev/csgt_vn.md
- dev/checkphatnguoi_vn.md
- dev/phatnguoi_vn.md
- 'Khác':
- other/references.md
- other/disclaimer.md
validation:
nav:
not_found: warn
omitted_files: warn
unrecognized_links: warn

extra:
analytics:
Expand Down
10 changes: 6 additions & 4 deletions requests/checkphatnguoi_vn.http
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
### Get for 6A64685
POST /phatnguoi
HOST: https://api.checkphatnguoi.vn
# Config
@plate = 30F88251

### Get for {{plate}}
POST https://api.checkphatnguoi.vn/phatnguoi
Content-Type: application/json

{"bienso": "60A64685"}
{"bienso": "{{plate}}"}
23 changes: 14 additions & 9 deletions requests/csgt_vn.http
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
### csgt
POST /?mod=contact&task=tracuu_post&ajax
HOST: www.csgt.vn
Cookie: PHPSESSID=jmg7m23ttkho70rap0fs6evgb0
# Config
@plate = 30F88251
@type = 1
@phpsessid = jmg7m23ttkho70rap0fs6evgb0
@captcha = rtz4rv

### Get data for {{plate}} with type {{type}}
POST www.csgt.vn/?mod=contact&task=tracuu_post&ajax
Cookie: PHPSESSID={{phpsessid}}
content-type: application/x-www-form-urlencoded

BienKS=60A64685 &
Xe=1 &
captcha=rtz4rv &
ipClient=9.9.9.91 &
cUrl=1
BienKS = {{plate}} &
Xe= {{type}} &
captcha = {{captcha}} &
ipClient = 9.9.9.91 &
cUrl = 1
9 changes: 6 additions & 3 deletions requests/phatnguoi_vn.http
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### phatnguoi.vn
GET /web/tra-cuu/30F88251/1
HOST: https://api.phatnguoi.vn
# Config
@plate = 30F88251
@type = 1

### Get data for {{plate}} with type {{type}}
GET https://api.phatnguoi.vn/web/tra-cuu/{{plate}}/{{type}}
7 changes: 3 additions & 4 deletions src/check_phat_nguoi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from logging import getLogger

from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.context.plates.context import plates_context
from check_phat_nguoi.context import plates_context
from check_phat_nguoi.get_data import GetData
from check_phat_nguoi.notify import SendNotifications
from check_phat_nguoi.print_console import PrintConsole

from .utils.setup_logger import setup_logger
from check_phat_nguoi.utils import setup_logger

logger = getLogger(__name__)

Expand All @@ -17,7 +16,7 @@ async def async_main() -> None:
logger.debug(f"Config read: {config}")
await GetData().get_data()
logger.debug(f"Data got: {plates_context.plates}")
await PrintConsole().print_console()
PrintConsole().print_console()
await SendNotifications().send()


Expand Down
10 changes: 5 additions & 5 deletions src/check_phat_nguoi/config/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Config(BaseModel):
default=(ApiEnum.checkphatnguoi_vn),
min_length=1,
)
print_console: bool = Field(
title="In thông tin ra console",
description="In thông tin của các biển ra console",
default=True,
)
pending_fines_only: bool = Field(
title="Lọc chưa nộp phạt",
description="Chỉ lọc các thông tin vi phạm chưa nộp phạt",
Expand All @@ -54,11 +59,6 @@ class Config(BaseModel):
description="Gửi và chờ tất cả request. Đối với API csgt.vn hãy tắt vì gửi request quá nhiều, trang lỗi. Nếu bật, các request sẽ không đảm bảo thứ tự input. Notify hiện không đảm bảo thứ tự input.",
default=True,
)
print_console: bool = Field(
title="In thông tin ra console",
description="In thông tin của biển vi phạm ra console",
default=True,
)
detail_log: bool = Field(
title="Log chi tiết",
description="Log chi tiết",
Expand Down
47 changes: 15 additions & 32 deletions src/check_phat_nguoi/context/plates/models/plate_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,9 @@ def __eq__(self, other: Any):
return self.plate == other.plate
return False

def __str__(self):
# TODO: Handle show details later when main updates that option
def __str__(self) -> str:
def create_violation_str(violation: ViolationDetail, index: int) -> str:
resolution_offices: str | None = (
"Nơi giải quyết vụ việc:"
+ "\n"
+ "\n".join(
resolution_office_detail.strip()
for resolution_office_detail in violation.resolution_offices_details
)
if violation.resolution_offices_details
else None
)
violation_str: str = (
f"Lỗi vi phạm thứ {index}:"
+ (f"\nMàu biển: {violation.color}" if violation.color else "")
Expand All @@ -64,29 +55,21 @@ def create_violation_str(violation: ViolationDetail, index: int) -> str:
else ""
)
)
# violation_str = "\n".join(
# line
# for line in f"""
# Lỗi vi phạm thứ {index}:
# Màu biển: {violation.color if violation.color else " "}
# Thời điểm vi phạm: {violation.date if violation.date else " "}
# Vị trí vi phạm: {violation.location if violation.location else " "}
# Hành vi vi phạm: {violation.violation if violation.violation else " "}
# Trạng thái: {"Đã xử phạt" if violation.status else ("Chưa xử phạt" if not violation.status else " ")}
# Đơn vị phát hiện vi phạm: {violation.enforcement_unit if violation.enforcement_unit else " "}
# """.splitlines()
# if line.strip()
# )
return (
"\n".join([violation_str, resolution_offices])
if resolution_offices
else violation_str
resolution_offices: str | None = (
"\n"
+ "Nơi giải quyết vụ việc:"
+ "\n"
+ "\n".join(
resolution_office_detail.strip()
for resolution_office_detail in violation.resolution_offices_details
)
if violation.resolution_offices_details
else None
)
return violation_str + (resolution_offices if resolution_offices else "")

plate_detail: str = (
f"Biển số: {self.plate}" + f"\nChủ sở hữu: {self.owner}"
if self.owner
else ""
plate_detail: str = f"Biển số: {self.plate}" + (
f"\nChủ sở hữu: {self.owner}" if self.owner else ""
)

if self.violations:
Expand Down
10 changes: 5 additions & 5 deletions src/check_phat_nguoi/get_data/engines/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .base_engine import BaseGetDataEngine
from .check_phat_nguoi import GetDataEngineCheckPhatNguoi
from .csgt import GetDataEngineCsgt
from .base import BaseGetDataEngine
from .check_phat_nguoi import CheckPhatNguoiGetDataEngine
from .csgt import CsgtGetDataEngine

__all__ = [
"BaseGetDataEngine",
"GetDataEngineCheckPhatNguoi",
"GetDataEngineCsgt",
"CheckPhatNguoiGetDataEngine",
"CsgtGetDataEngine",
]
32 changes: 0 additions & 32 deletions src/check_phat_nguoi/get_data/engines/base_session.py

This file was deleted.

12 changes: 8 additions & 4 deletions src/check_phat_nguoi/get_data/engines/check_phat_nguoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
VehicleTypeEnum,
get_vehicle_enum,
)
from check_phat_nguoi.utils import HttpaioSession

from .base_engine import BaseGetDataEngine
from .base_session import BaseGetDataSession
from .base import BaseGetDataEngine

logger = getLogger(__name__)


class GetDataEngineCheckPhatNguoi(BaseGetDataEngine, BaseGetDataSession):
class CheckPhatNguoiGetDataEngine(BaseGetDataEngine, HttpaioSession):
api: ApiEnum = ApiEnum.checkphatnguoi_vn
headers: Final[dict[str, str]] = {"Content-Type": "application/json"}

def __init__(self) -> None:
super().__init__(session_header=self.headers)
HttpaioSession.__init__(self, headers=self.headers)

@staticmethod
def get_violations(
Expand Down Expand Up @@ -112,3 +112,7 @@ async def get_data(self, plate_info: PlateInfo) -> PlateDetail | None:
type=type,
violations=self.get_violations(plate_detail_dict, type),
)

@override
async def __aexit__(self, exc_type, exc_value, exc_traceback) -> None:
return await HttpaioSession.__aexit__(self, exc_type, exc_value, exc_traceback)
16 changes: 10 additions & 6 deletions src/check_phat_nguoi/get_data/engines/csgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from check_phat_nguoi.constants import DATETIME_FORMAT_CHECKPHATNGUOI as DATETIME_FORMAT
from check_phat_nguoi.context import PlateDetail, ViolationDetail
from check_phat_nguoi.types import ApiEnum, VehicleTypeEnum, get_vehicle_enum
from check_phat_nguoi.utils import HttpaioSession

from .base_engine import BaseGetDataEngine
from .base_session import BaseGetDataSession
from .base import BaseGetDataEngine

logger = getLogger(__name__)

Expand All @@ -31,12 +31,12 @@
SSL_CONTEXT.set_ciphers("DEFAULT@SECLEVEL=1")


class _GetDataLocalEngineCsgt(BaseGetDataSession):
class _GetDataCsgtCoreEngine(HttpaioSession):
api: ApiEnum = ApiEnum.csgt_vn

def __init__(self, plate_info: PlateInfo) -> None:
self._plate_info: PlateInfo = plate_info
super().__init__()
HttpaioSession.__init__(self)

@staticmethod
def _bypass_captcha(captcha_img: bytes) -> str:
Expand Down Expand Up @@ -178,10 +178,14 @@ async def get_data(self) -> PlateDetail | None:
f"Plate {self._plate_info.plate}: Error occurs while getting data (internally) {self.api.value}. {e}"
)

@override
async def __aexit__(self, exc_type, exc_value, exc_traceback) -> None:
return await HttpaioSession.__aexit__(self, exc_type, exc_value, exc_traceback)


class GetDataEngineCsgt(BaseGetDataEngine):
class CsgtGetDataEngine(BaseGetDataEngine):
@override
async def get_data(self, plate_info: PlateInfo) -> PlateDetail | None:
async with _GetDataLocalEngineCsgt(plate_info) as local_engine:
async with _GetDataCsgtCoreEngine(plate_info) as local_engine:
plate_detail: PlateDetail | None = await local_engine.get_data()
return plate_detail
Loading

0 comments on commit 0acd960

Please sign in to comment.