#!/usr/bin/env python3
# LeakRadar-Survey: Krypto-Oekosystem-Domains (Payment-Anbieter, Swap-Plattformen, Magazine, Foren)
import json, time, os, urllib.request

TOKEN = open(os.path.expanduser('~/.secrets/leakradar_paid_token.txt')).read().strip()
API = "https://api.leakradar.io"

DOMAINS = [
    # Payment-Anbieter (kleinere)
    "coingate.com", "plisio.net", "coinremitter.com", "cryptapi.io",
    "nowpayments.io", "coinspaid.io", "coinpayments.net", "mugglepay.io",
    # kleine Swap-Plattformen (nicht im Forex-500-Angriff)
    "simpleswap.io", "stealthex.io", "sideshift.ai", "fixedfloat.com",
    "godex.io", "exolix.com",
    # Magazine/Newsletter DACH
    "btc-echo.de", "kryptokompass.com", "crypto-radio.de", "cryptonomist.ch",
    "krypto-magazin.de", "blockchainwelt.de", "bitcoinforum.de",
    # weitere Krypto-Oekosystem
    "coinmarketcap.com", "coinpayments.io",
]

def curl(path):
    for attempt in range(3):
        try:
            r = urllib.request.Request(API + path)
            r.add_header('Authorization', 'Bearer ' + TOKEN)
            with urllib.request.urlopen(r, timeout=60) as resp:
                return json.loads(resp.read())
        except Exception as e:
            time.sleep(3)
    return None

out = {}
for d in DOMAINS:
    r = curl(f"/search/domain/{d}")
    if r is None:
        out[d] = {"error": "failed"}
    else:
        out[d] = {k: r.get(k) for k in ['customers_compromised','employees_compromised','third_parties_compromised']}
        if r.get('blacklisted_value'):
            out[d]['blacklisted'] = True
    print(d, out[d], flush=True)
    time.sleep(1.2)

with open(os.path.expanduser('~/krypto-angriff/lr_survey_crypto.json'), 'w') as f:
    json.dump(out, f, indent=1)
print('saved')
