hotpocket/services/backend/hotpocket_backend/apps/bot/conf.py
Tomek Wójcik b4338e2769
Some checks failed
CI / Checks (push) Failing after 13m2s
Release v1.0.0
2025-08-20 21:00:50 +02:00

55 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import dataclasses
from .types import PStrategy
DEFAULT_STRATEGY = 'hotpocket_backend.apps.bot.strategy.basic:BasicStrategy'
DEFAULT_BANNED_HOSTNAMES = [
# YT returns dummy data when I try to fetch the page and extract
# metadata. I'd have to use Google APIs for that and it's 11:30 PM...
'youtube.com',
'youtu.be',
# Reddit's response is too generic to pull any useful info from it.
# Since they forced Apollo to shut down, I refuse to even think about
# interacting with their API :P.
'reddit.com',
# Twitter, amirite?
'twitter.com',
't.co',
'x.com',
]
@dataclasses.dataclass(kw_only=True)
class Settings:
STRATEGY: str
BANNED_HOSTNAMES: list[str]
def get_strategy(self, *, url: str) -> PStrategy:
from hotpocket_common.loader import load_module_attribute
strategy = load_module_attribute(self.STRATEGY)
return strategy(url)
def from_django_settings() -> Settings:
from django.conf import settings
return Settings(
STRATEGY=getattr(
settings,
'HOTPOCKET_BOT_STRATEGY',
DEFAULT_STRATEGY,
),
BANNED_HOSTNAMES=getattr(
settings,
'HOTPOCKET_BOT_BANNED_HOSTNAMES',
DEFAULT_BANNED_HOSTNAMES,
),
)
bot_settings: Settings = None # type: ignore[assignment]