import sqlite3 import pandas as pd def audit_links(): conn = sqlite3.connect('data/hiffi_catalog.db') query = """ WITH latest AS ( SELECT t.*, ROW_NUMBER() OVER (PARTITION BY t.artist_id ORDER BY t.last_synced_at DESC) as rn FROM telemetry_metrics t ) SELECT a.artist_name, a.spotify_url, a.youtube_url, a.instagram_url, l.spotify_monthly_listeners as spt, l.subscribers_count as yt, l.instagram_followers as ig FROM artists a LEFT JOIN latest l ON a.artist_id = l.artist_id AND l.rn = 1 WHERE a.image_verified_flag = 1 """ df = pd.read_sql_query(query, conn) # Fill missing with 1 to avoid division errors df[['spt', 'yt', 'ig']] = df[['spt', 'yt', 'ig']].fillna(1) df.replace(0, 1, inplace=True) df['spt_to_yt'] = df['spt'] / df['yt'] df['flag'] = '✅ Legit' # If Spotify audience is 100x bigger than YouTube, the YT link might be a fake fan channel df.loc[df['spt_to_yt'] > 100, 'flag'] = '⚠️ Check YT Link' df = df.sort_values('flag', ascending=False) html = "
| Status | Artist | Spotify Listeners | YouTube Subs | Spotify Link | YouTube Link |
|---|---|---|---|---|---|
| {row['flag']} | {row['artist_name']} | " html += f"{int(row['spt']):,} | {int(row['yt']):,} | " html += f"SPT | " html += f"YT |