import os
from pydantic_settings import BaseSettings
from typing import Optional
class Settings(BaseSettings):
"""Application settings"""
# Server Configuration
SERVER_HOST: str = "0.0.0.0"
SERVER_PORT: int = 8000
FRONTEND_URL: str = "http://localhost:3000"
# Database Configuration
DATABASE_URL: str = "sqlite:///./locate_the_news.db"
# NewsAPI Configuration
NEWSAPI_KEY: Optional[str] = None
NEWSAPI_COUNTRIES: str = "us,gb,de,fr,za,ng,eg,ke,jp,br,ar,co,cl,mx,in,au"
NEWSAPI_CATEGORIES: str = "general,technology,business,health,science"
# NLP/Geocoding Settings
SPACY_MODEL_NAME: str = "en_core_web_sm"
GEOCODER_USER_AGENT: str = "LocateTheNews/1.0.0"
GEOCODER_TIMEOUT: int = 10
# Sentiment Analysis Thresholds
SENTIMENT_THRESHOLD_NEGATIVE: float = -0.3
SENTIMENT_THRESHOLD_POSITIVE: float = 0.3
# Priority Detection Keywords
PRIORITY_KEYWORDS: str = "earthquake,tsunami,terror,attack,shooting,explosion,disaster,emergency,breaking,urgent,critical"
# RSS Sources
BBC_NEWS_WORLD_RSS: str = "http://feeds.bbci.co.uk/news/world/rss.xml"
# Additional settings
MAPBOX_TOKEN: Optional[str] = None
RSS_FEEDS: list = [
"https://www.euronews.com/rss",
"http://feeds.bbci.co.uk/news/rss.xml",
"https://tr.euronews.com/rss"
]
class Config:
env_file = ".env"
case_sensitive = True
@property
def priority_keywords_list(self) -> list[str]:
return [k.strip() for k in self.PRIORITY_KEYWORDS.split(",") if k.strip()]
@property
def newsapi_countries_list(self) -> list[str]:
return [c.strip() for c in self.NEWSAPI_COUNTRIES.split(",") if c.strip()]
@property
def rss_sources_list(self) -> list[dict[str, str]]:
# Map simple URL list to expected dictionary format
# If the code expects name and url, we can infer some names or just use a default
sources = []
for url in self.RSS_FEEDS:
name = "News Source"
if "euronews" in url:
name = "Euronews"
elif "bbc" in url:
name = "BBC News"
elif "trthaber" in url:
name = "TRT Haber"
sources.append({"name": name, "url": url})
return sources
# Create settings instance
settings = Settings()