import requests, io, sys, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
H = {'User-Agent': 'Mozilla/5.0'}

# 1) Aptoide search API
try:
    r = requests.get('https://ws75.aptoide.com/api/7/apps/search?query=vinfast&limit=25', headers=H, timeout=20)
    print('[aptoide] status', r.status_code)
    if r.status_code == 200:
        d = r.json()
        for a in (d.get('datalist') or {}).get('list', []):
            name = a.get('name'); pid = a.get('package'); ver = a.get('file', {}).get('vername')
            size = a.get('filesize', 0); apk = a.get('file', {}).get('path')
            print(f'  {pid:45s} {name:30s} v{ver} {size//1048576}MB')
            print(f'     path: {apk}')
except Exception as e:
    print('[aptoide] EXC', type(e).__name__, e)
