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 = "

Link Authenticity Audit

" html += "" for _, row in df.iterrows(): bg = "#4a1919" if "⚠️" in row['flag'] else "transparent" html += f"" html += f"" html += f"" html += f"" html += "
StatusArtistSpotify ListenersYouTube SubsSpotify LinkYouTube Link
{row['flag']}{row['artist_name']}{int(row['spt']):,}{int(row['yt']):,}SPTYT
" with open('data/link_audit_report.html', 'w', encoding='utf-8') as f: f.write(html) print("Audit saved to data/link_audit_report.html - open it in your browser.") conn.close() if __name__ == "__main__": audit_links()