import json
import urllib.request

with open('software.json') as f:
    apps = json.load(f)
# Languages format à déduire. Skip pour l'instant.

RP_ID = 70

# Apps à traiter (déjà triées par étoiles, desc)
todo = []
done_slugs = {'caddy', 'traefik', 'nginx-proxy-manager', 'pangolin', 'haproxy'}

for app in apps:
    primary_tags = app[17] if isinstance(app[17], list) else []
    if RP_ID in primary_tags:
        slug = app[2]
        if slug in done_slugs:
            continue
        todo.append({
            'id': app[0],
            'name': app[1],
            'slug': slug,
            'url': app[3],
            'repo': app[4],
            'desc': app[5],
            'stars': int(app[13]),
            'updated': app[15],
            'tags': primary_tags,
            'is_primary': primary_tags[0] == RP_ID,
        })

todo.sort(key=lambda x: -x['stars'])
print(f'À traiter: {len(todo)}')
for a in todo:
    print(f'  {a["slug"]} | {a["name"]} | {a["stars"]}★')

with open('rp-todo.json', 'w') as f:
    json.dump(todo, f, indent=2, ensure_ascii=False)
