|
|
from pydantic_settings import BaseSettings, SettingsConfigDict |
|
|
from urllib.parse import quote_plus |
|
|
|
|
|
|
|
|
class Settings(BaseSettings): |
|
|
""" |
|
|
Manages application settings and loads environment variables from a .env file. |
|
|
It constructs the complete MongoDB connection string from individual components. |
|
|
""" |
|
|
|
|
|
|
|
|
DB_NAME: str |
|
|
|
|
|
|
|
|
SENTIMENT_MODEL: str |
|
|
|
|
|
|
|
|
YT_API_KEY: str |
|
|
|
|
|
|
|
|
MONGODB_URI: str |
|
|
MONGODB_USR: str |
|
|
MONGODB_PWD: str |
|
|
|
|
|
|
|
|
FETCH_NUM_ENTITIES: int = 20 |
|
|
FETCH_VIDEOS_PER_ENTITY: int = 5 |
|
|
FETCH_COMMENTS_PER_VIDEO: int = 100 |
|
|
FETCH_TOTAL_COMMENTS_PER_ENTITY: int = 500 |
|
|
FETCH_TRENDS_GEO: str = "US" |
|
|
FETCH_TRENDS_WITHIN_DAYS: int = 7 |
|
|
|
|
|
|
|
|
CONSUMER_BATCH_SIZE: int = 32 |
|
|
CONSUMER_BATCH_TIMEOUT_SECONDS: int = 5 |
|
|
|
|
|
|
|
|
HF_HOME: str = "/data" |
|
|
TRANSFORMERS_CACHE: str = "./.cache" |
|
|
|
|
|
|
|
|
API_PREFIX: str = "/api" |
|
|
API_VERSION: str = "/v1" |
|
|
API_PREFIX_TRENDS: str |
|
|
DEBUG: bool = False |
|
|
|
|
|
|
|
|
QSTASH_URL: str = "https://qstash.upstash.io" |
|
|
QSTASH_TOKEN: str |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BASE_URL: str = "http://localhost:8000" |
|
|
|
|
|
|
|
|
HOME_PAGE_ENTITIES_LIMIT: int = 10 |
|
|
REPRESENTATIVE_COMMENTS_LIMIT: int = 3 |
|
|
|
|
|
|
|
|
ON_DEMAND_COMMENTS_PER_VIDEO: int = 100 |
|
|
ON_DEMAND_TOTAL_COMMENTS: int = 500 |
|
|
|
|
|
|
|
|
INFERENCE_BATCH_SIZE: int = 32 |
|
|
|
|
|
|
|
|
model_config = SettingsConfigDict( |
|
|
env_file=".env", env_file_encoding="utf-8", extra="ignore" |
|
|
) |
|
|
|
|
|
@property |
|
|
def MONGODB_CONNECTION_STRING(self) -> str: |
|
|
""" |
|
|
Constructs and returns the full MongoDB connection string, |
|
|
properly escaping the username and password. |
|
|
""" |
|
|
|
|
|
escaped_usr = quote_plus(self.MONGODB_USR) |
|
|
escaped_pwd = quote_plus(self.MONGODB_PWD) |
|
|
|
|
|
|
|
|
return self.MONGODB_URI.replace("<username>", escaped_usr).replace( |
|
|
"<password>", escaped_pwd |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
settings = Settings() |
|
|
|