import json, re, ssl, urllib.request

CTX = ssl._create_unverified_context()


def get(u, n=60000):
    req = urllib.request.Request(u, headers={'User-Agent': 'Mozilla/5.0'})
    r = urllib.request.urlopen(req, timeout=12, context=CTX)
    return r.read(n).decode('utf-8', 'replace')


for repo in ('raw-hosted', 'maven-releases', 'npm-hosted', 'pypi-hosted'):
    try:
        d = json.loads(get('https://10.112.205.15/service/rest/v1/search?repository=%s&sort=name' % repo, 200000))
        items = d.get('items', [])
        print('==', repo, 'items', len(items), 'token', bool(d.get('continuationToken')))
        for it in items[:12]:
            print('   ', it.get('name'), '|', (it.get('assets') or [{}])[0].get('downloadUrl', ''))
    except Exception as e:
        print('==', repo, 'ERR', type(e).__name__, str(e)[:90])

for u in ('https://100.64.3.75/', 'https://100.64.2.38/'):
    try:
        h = get(u, 200000)
        links = [x for x in re.findall(r'href="([^"]+)"', h) if not x.startswith('?') and not x.startswith('/icons')]
        print('== listing', u, len(links))
        print('   ', ' '.join(links[:40]))
    except Exception as e:
        print('== listing', u, 'ERR', type(e).__name__, str(e)[:90])
