Files

76 lines
3.2 KiB
Python
Raw Permalink Normal View History

import os
import sqlite3
import pandas as pd
CSV_PATH = 'data/hiffi_multiplatform_500.csv'
DB_PATH = 'data/hiffi_catalog.db'
HTML_OUT = 'audit_top500_profiles.html'
df = pd.read_csv(CSV_PATH)
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
cur = conn.cursor()
db_meta = {
str(r['artist_id']): dict(r)
for r in cur.execute('SELECT artist_id, country_origin FROM artists').fetchall()
}
missing_origin = []
cards_html = []
for idx, row in df.iterrows():
aid = str(row.get('artist_id'))
name = row.get('name') or row.get('artist_name')
origin = row.get('country_origin') or db_meta.get(aid, {}).get('country_origin') or 'Unknown'
if origin == 'Unknown' or pd.isna(origin):
missing_origin.append((aid, name))
img = row.get('image_url')
img_name = os.path.basename(str(img).strip())
rel_img_path = f'data/artist_avatars/{img_name}'
yt = row.get('youtube_url') if pd.notna(row.get('youtube_url')) else '#'
sp = row.get('spotify_url') if pd.notna(row.get('spotify_url')) else '#'
ig = row.get('instagram_url') if pd.notna(row.get('instagram_url')) else '#'
card = f"""
<div style="border:1px solid #ddd; border-radius:8px; padding:10px; width:160px; text-align:center; background:#ffffff; font-family:sans-serif; box-shadow:0 1px 3px rgba(0,0,0,0.08);">
<img src="{rel_img_path}" alt="{name}" style="width:140px; height:140px; object-fit:cover; border-radius:6px; border:1px solid #ccc;" onerror="this.src='https://via.placeholder.com/140?text=No+Image'" />
<div style="font-weight:bold; font-size:13px; margin-top:8px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="{name}">#{idx+1} {name}</div>
<div style="font-size:11px; color:#666; margin-top:2px; margin-bottom:6px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" title="{origin}">{origin}</div>
<div style="font-size:12px;">
<a href="{sp}" target="_blank" style="text-decoration:none; margin:0 3px;" title="Spotify">🟢</a>
<a href="{yt}" target="_blank" style="text-decoration:none; margin:0 3px;" title="YouTube">🔴</a>
<a href="{ig}" target="_blank" style="text-decoration:none; margin:0 3px;" title="Instagram">🟣</a>
</div>
</div>
"""
cards_html.append(card)
full_html = f"""<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HIFFI Top 500 - Visual Portrait & Metadata Audit</title>
</head>
<body style="background:#f4f6f8; padding:24px; font-family:sans-serif;">
<h2 style="margin-bottom:4px;">HIFFI Top 500 - Visual Portrait & Metadata Audit</h2>
<p style="color:#555; margin-bottom:20px;">Review real human face presence, 1:1 square framing, and canonical platform routing.</p>
<div style="display:flex; flex-wrap:wrap; gap:12px;">
{''.join(cards_html)}
</div>
</body>
</html>"""
with open(HTML_OUT, 'w', encoding='utf-8') as f:
f.write(full_html)
print('=== METADATA COMPLETENESS AUDIT ===')
print(f'Total cohort evaluated: {len(df)}')
print(f'Missing Country/City Origin: {len(missing_origin)}')
if missing_origin:
print('Sample missing origins:', missing_origin[:10])
print(f'\nVisual gallery successfully generated at: {HTML_OUT}')