fix(admin): Naprawiono błąd importu w SSE scraping endpoint
Problem: Podwójny import ZOPKContentScraper powodował błąd 'cannot access local variable' Rozwiązanie: Przeniesiono import na początek funkcji generate() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
37af8abc73
commit
900a3b4ed9
22
app.py
22
app.py
@ -11212,36 +11212,20 @@ def admin_zopk_scrape_content_stream():
|
||||
|
||||
def generate():
|
||||
import json
|
||||
from dataclasses import asdict
|
||||
import time
|
||||
from zopk_content_scraper import ZOPKContentScraper, MAX_RETRY_ATTEMPTS
|
||||
from database import ZOPKNews
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
scraper = ZOPKContentScraper(db, user_id=user_id)
|
||||
|
||||
def progress_callback(update):
|
||||
data = asdict(update)
|
||||
yield f"data: {json.dumps(data, ensure_ascii=False)}\n\n"
|
||||
|
||||
# This won't work with generator, need different approach
|
||||
# Use a queue-based approach instead
|
||||
|
||||
progress_updates = []
|
||||
|
||||
def queue_callback(update):
|
||||
progress_updates.append(update)
|
||||
|
||||
# Run in this thread, yielding updates as they come
|
||||
from zopk_content_scraper import ZOPKContentScraper, ProgressUpdate
|
||||
import time
|
||||
|
||||
# Get articles to scrape
|
||||
from database import ZOPKNews
|
||||
query = db.query(ZOPKNews).filter(
|
||||
ZOPKNews.status.in_(['approved', 'auto_approved'])
|
||||
)
|
||||
|
||||
if not force:
|
||||
from zopk_content_scraper import MAX_RETRY_ATTEMPTS
|
||||
query = query.filter(ZOPKNews.scrape_status.in_(['pending', 'failed']))
|
||||
query = query.filter(
|
||||
(ZOPKNews.scrape_status == 'pending') |
|
||||
|
||||
Loading…
Reference in New Issue
Block a user