feat: make scraper and job service account-aware
- OptimizedTelegramScraper accepts account_id parameter; sets DATA_DIR to data/accounts/<id>/ when provided - Session path uses account_session_path() for per-account session files - initialize_client() reads per-account credentials from account state store - ScraperJobService passes account_id from payload to scraper constructor - Per-account state loaded from AccountStateStore before scraping
This commit is contained in:
+12
-3
@@ -1,6 +1,6 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from app_state import StateStore
|
||||
|
||||
@@ -25,12 +25,21 @@ class ScraperJobService:
|
||||
asyncio.run(self._run_async(job_type, payload))
|
||||
|
||||
async def _run_async(self, job_type: str, payload: Dict[str, Any]) -> None:
|
||||
# Extract account_id from payload, default to None (legacy)
|
||||
account_id: Optional[str] = payload.get("account_id")
|
||||
ScraperClass = self._import_scraper_class()
|
||||
scraper = ScraperClass()
|
||||
scraper = ScraperClass(account_id=account_id)
|
||||
|
||||
if account_id:
|
||||
from app_state import load_account
|
||||
acc_state = load_account(self.state_store.path.parent, account_id)
|
||||
# Load per-account state into scraper state
|
||||
scraper.state = acc_state
|
||||
|
||||
initialized = await scraper.initialize_client(interactive=False)
|
||||
if not initialized:
|
||||
raise RuntimeError(
|
||||
"Telegram client is not ready. Check credentials, session, and write access to /app/session."
|
||||
"Telegram client is not ready. Check credentials, session, and write access."
|
||||
)
|
||||
try:
|
||||
if job_type == "scrape_channel":
|
||||
|
||||
Reference in New Issue
Block a user