You've already forked hotpocket
This commit is contained in:
54
services/backend/hotpocket_backend/apps/bot/conf.py
Normal file
54
services/backend/hotpocket_backend/apps/bot/conf.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- 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]
|
||||
Reference in New Issue
Block a user