#!/usr/bin/env python3
# PRESALE-JAGD: LeakRadar Gratis-Zaehlungen (/search/domain) fuer Launchpad-/ICO-/Airdrop-Plattformen
# NUR Counts (gratis) — Pools dem Parent melden, Cron zieht sie spaeter.
import json, time, os, urllib.request

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

DOMAINS = [
    # Launchpads / Presale-Plattformen
    "pinksale.finance", "dxsale.network", "dao-maker.xyz", "polkastarter.com",
    "trustswap.org", "seedify.fund", "bscpad.com", "gamefi.org",
    "poolz.finance", "bounce.finance", "coinlist.co", "seedify.com",
    "redkite.finance", "trustpad.io", "duckdao.io", "poolz.finance",
    # ICO-/Airdrop-Medien & Tracker
    "icodrops.com", "coincarp.com", "dyor.io", "airdropalert.com",
    "coinmarketcap.com", "coingecko.com", "coinmarketcap.io",
    # Wallets / Web3 (presale-affin)
    "trustwallet.com", "metamask.io", "coinbase.com",
    # Grosse Exchanges mit Launchpad
    "binance.com", "kucoin.com", "gate.io", "okx.com", "bybit.com", "mexc.com",
    "bitmart.com", "huobi.com",
    # Krypto-Medien DACH
    "btc-echo.de", "kryptokompass.com", "blockchainwelt.de", "bitcoinforum.de",
    "beincrypto.com", "cryptoticker.io",
    # Crowdfunding / ICO-Nahe
    "hitbtc.com", "whitebit.com", "pancakeswap.finance", "uniswap.org",
    "etherscan.io", "tronscan.org", "dappradar.com", "debank.com",
]

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:
            print('  retry', e, flush=True)
            time.sleep(4)
    return None

out = {}
if os.path.exists('lr_presale_counts.json'):
    out = json.load(open('lr_presale_counts.json'))
for d in DOMAINS:
    if d in out: continue
    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)
    json.dump(out, open('lr_presale_counts.json','w'), indent=1)
    time.sleep(1.2)
print('DONE', len(out))
