41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
from hotpocket_backend.apps.bot.services import BotService as BackendBotService
|
|
from hotpocket_soa.dto import BotResultOut
|
|
|
|
from .base import ProxyService, SOAError
|
|
|
|
|
|
class BotService(ProxyService):
|
|
class BotServiceError(SOAError):
|
|
pass
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.backend_associations_service = BackendBotService()
|
|
|
|
def wrap_exception(self, exception: Exception) -> Exception:
|
|
new_exception_args = []
|
|
if len(exception.args) > 0:
|
|
new_exception_args = [exception.args[0]]
|
|
|
|
return self.BotServiceError(*new_exception_args)
|
|
|
|
def is_netloc_banned(self, *, url: str) -> bool:
|
|
return self.call(
|
|
self.backend_associations_service,
|
|
'is_netloc_banned',
|
|
url=url,
|
|
)
|
|
|
|
def handle(self, *, url: str) -> BotResultOut:
|
|
return BotResultOut.model_validate(
|
|
self.call(
|
|
self.backend_associations_service,
|
|
'handle',
|
|
url=url,
|
|
),
|
|
from_attributes=True,
|
|
)
|