feat: finalize root api.py with X-Auth-Secret auth security and clean pure sales cohort
This commit is contained in:
1 parent
85e6395770
commit
78a46a8dbe
629 files changed
+123965
-755
No files matched your search
@@ -0,0 +1,57 @@
|
||||
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 = "<html><body style='background:#121212; color:#fff; font-family:sans-serif;'><h2>Link Authenticity Audit</h2><table border='1' style='border-collapse:collapse; padding:5px;'>"
|
||||
html += "<tr><th>Status</th><th>Artist</th><th>Spotify Listeners</th><th>YouTube Subs</th><th>Spotify Link</th><th>YouTube Link</th></tr>"
|
||||
|
||||
for _, row in df.iterrows():
|
||||
bg = "#4a1919" if "⚠️" in row['flag'] else "transparent"
|
||||
html += f"<tr style='background:{bg}'><td>{row['flag']}</td><td>{row['artist_name']}</td>"
|
||||
html += f"<td>{int(row['spt']):,}</td><td>{int(row['yt']):,}</td>"
|
||||
html += f"<td><a href='{row['spotify_url']}' style='color:#1DB954'>SPT</a></td>"
|
||||
html += f"<td><a href='{row['youtube_url']}' style='color:#FF0000'>YT</a></td></tr>"
|
||||
|
||||
html += "</table></body></html>"
|
||||
|
||||
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()
|
||||
Reference in new issue
Block a user