Files
hack/tools/scripts/scan_channels.py
T

26 lines
825 B
Python

#!/usr/bin/env python3
"""Parallel scan all channel IDs, write /tmp/chans.json."""
import sys, json
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor, as_completed
sys.path.insert(0, str(Path(__file__).resolve().parent))
import newapi_client as n
def scan(cid):
try:
c = n.get_channel(cid)
return c if c and c.get("id") else None
except Exception:
return None
chans = []
with ThreadPoolExecutor(max_workers=24) as ex:
futs = {ex.submit(scan, cid): cid for cid in range(1, 850)}
for f in as_completed(futs):
r = f.result()
if r: chans.append(r)
chans.sort(key=lambda c: c["id"])
json.dump(chans, open("/tmp/chans.json", "w"))
import collections
print("total:", len(chans), "status:", dict(collections.Counter(c.get("status") for c in chans)))