#!/usr/bin/env python # Usage: # wget -O relays.json https://onionoo.torproject.org/details?type=relay # ./nodeinfo < relays.json import datetime import json import sys DATEFMT = "%Y-%m-%d %H:%M:%S" FAMILY_LABELS = {} def family_label(r): try: effective_family = r["effective_family"] except KeyError: return None key = [f[1:] for f in effective_family] key.append(r["fingerprint"]) key = tuple(sorted(key)) try: return FAMILY_LABELS[key] except KeyError: label = chr(ord("A") + len(FAMILY_LABELS)) FAMILY_LABELS[key] = label return label now = datetime.datetime.utcnow() def output_relay(r): try: fingerprint = r["fingerprint"] except KeyError: fingerprint = r["hashed_fingerprint"] print "%s %-17s %s %s %s %-26s %s" % ( fingerprint, r["nickname"], r["first_seen"].format(DATEFMT), r["last_seen"].format(DATEFMT), r["last_restarted"].format(DATEFMT), r["platform"], ",".join(r.get("transports", ())), ) j = json.load(sys.stdin) for r in j["relays"] + j["bridges"]: # if r["fingerprint"] in OLD_FINGERPRINTS.intersection(FINGERPRINTS): # if r["fingerprint"] in FINGERPRINTS: output_relay(r)