import json

with open('software.json') as f:
    apps = json.load(f)

RP_ID = 70  # Reverse Proxy

rp_apps = []
for app in apps:
    primary_tags = app[17] if isinstance(app[17], list) else []
    if RP_ID in primary_tags:
        # Indice du primary
        is_primary = primary_tags[0] == RP_ID
        rp_apps.append({
            'id': app[0],
            'name': app[1],
            'slug': app[2],
            'url': app[3],
            'repo': app[4],
            'desc': app[5],
            'lang_id': app[7],
            'stars': app[13],
            'updated': app[15],
            'tags': primary_tags,
            'is_primary': is_primary,
        })

# Tri par étoiles
rp_apps.sort(key=lambda x: -int(x['stars']))

print(f'Total apps reverse-proxy: {len(rp_apps)}')
print()
print(f'{"Slug":35s} {"Nom":30s} {"⭐":>8s} P/S MAJ')
for a in rp_apps:
    flag = 'P' if a['is_primary'] else 'S'
    print(f'  {a["slug"]:35s} {a["name"]:30s} {a["stars"]:>8} {flag} {a["updated"]}')
