feat: trigger Facebook Graph API sync during enrichment scan
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Instead of skipping OAuth-connected Facebook profiles, the enrichment scan now calls sync_facebook_to_social_media() to fetch fresh data via Graph API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
10b116cd6a
commit
60dd646989
@ -893,8 +893,22 @@ def _run_enrichment_background(company_ids):
|
||||
}
|
||||
|
||||
if profile.source in ('facebook_api',):
|
||||
profile_result['status'] = 'skipped'
|
||||
profile_result['reason'] = 'Dane z API (wyższy priorytet)'
|
||||
# Sync via Graph API instead of scraping
|
||||
try:
|
||||
from facebook_graph_service import sync_facebook_to_social_media
|
||||
sync_result = sync_facebook_to_social_media(db, company_id)
|
||||
if sync_result.get('success'):
|
||||
data = sync_result.get('data', {})
|
||||
profile_result['status'] = 'synced_api'
|
||||
profile_result['reason'] = f"Zsynchronizowano przez Graph API ({data.get('followers_count', 0)} obserwujących, engagement: {data.get('engagement_rate', 0):.1f}%)"
|
||||
company_result['has_changes'] = True
|
||||
else:
|
||||
profile_result['status'] = 'error'
|
||||
profile_result['reason'] = f"Graph API: {sync_result.get('error', 'nieznany błąd')}"
|
||||
except Exception as e:
|
||||
logger.warning(f"Facebook API sync failed for {company.name}: {e}")
|
||||
profile_result['status'] = 'error'
|
||||
profile_result['reason'] = f"Graph API sync error: {str(e)[:100]}"
|
||||
company_result['profiles'].append(profile_result)
|
||||
continue
|
||||
|
||||
@ -1142,7 +1156,7 @@ def admin_social_audit_enrichment_review():
|
||||
# Summary stats
|
||||
total_profiles_scanned = sum(len(r.get('profiles', [])) for r in results)
|
||||
profiles_with_changes = len(pending)
|
||||
profiles_skipped = sum(1 for r in results for p in r.get('profiles', []) if p.get('status') == 'skipped')
|
||||
profiles_skipped = sum(1 for r in results for p in r.get('profiles', []) if p.get('status') in ('skipped', 'synced_api'))
|
||||
profiles_no_data = sum(1 for r in results for p in r.get('profiles', []) if p.get('status') in ('no_data', 'no_changes'))
|
||||
profiles_errors = sum(1 for r in results for p in r.get('profiles', []) if p.get('status') == 'error')
|
||||
companies_with_changes = len(set(c['company_id'] for c in pending))
|
||||
|
||||
@ -178,8 +178,8 @@
|
||||
<span class="review-stat-label">Z nowymi danymi</span>
|
||||
</div>
|
||||
<div class="review-stat">
|
||||
<span class="review-stat-value gray">{{ summary.profiles_skipped }}</span>
|
||||
<span class="review-stat-label">Pominiętych (API)</span>
|
||||
<span class="review-stat-value blue">{{ summary.profiles_skipped }}</span>
|
||||
<span class="review-stat-label">Sync API (OAuth)</span>
|
||||
</div>
|
||||
<div class="review-stat">
|
||||
<span class="review-stat-value gray">{{ summary.profiles_no_data }}</span>
|
||||
@ -242,7 +242,7 @@
|
||||
</div>
|
||||
<div class="company-review-body hidden">
|
||||
{% for p in result.profiles %}
|
||||
<div class="platform-diff {{ p.status if p.status in ('error', 'skipped') else ('no-changes' if p.status == 'no_changes' else '') }}">
|
||||
<div class="platform-diff {{ p.status if p.status in ('error', 'skipped') else ('no-changes' if p.status in ('no_changes', 'synced_api') else '') }}">
|
||||
<div class="platform-diff-header">
|
||||
<span style="text-transform: capitalize;">{{ p.platform }}</span>
|
||||
{% if p.status == 'changes' %}
|
||||
@ -253,6 +253,8 @@
|
||||
<span style="color: #ef4444; font-size: var(--font-size-xs); font-weight: 400;">{{ p.reason }}</span>
|
||||
{% elif p.status == 'no_data' %}
|
||||
<span style="color: #9ca3af; font-size: var(--font-size-xs); font-weight: 400;">{{ p.get('reason', 'Brak nowych danych') }}</span>
|
||||
{% elif p.status == 'synced_api' %}
|
||||
<span style="color: #3b82f6; font-size: var(--font-size-xs); font-weight: 400;">{{ p.reason }}</span>
|
||||
{% elif p.status == 'no_changes' %}
|
||||
<span style="color: #22c55e; font-size: var(--font-size-xs); font-weight: 400;">Dane aktualne</span>
|
||||
{% endif %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user