#!/usr/bin/env python3
import json, os, time
import requests

key = None
for line in open(os.path.expanduser("~/.hermes/.env")):
    if line.startswith("GETXAPI_KEY="):
        key = line.split("=", 1)[1].strip()
        break
H = {"Authorization": f"Bearer {key}"}
BASE = "https://api.getxapi.com/twitter"

HANDLES = ["kloss_xyz", "EXM7777", "PrajwalTomar_", "ayushsoni_io", "Mnilax",
           "Defi_Scribbler", "Av1dlive", "intleverage", "frederickjames", "adenwron"]

for h in HANDLES:
    try:
        r = requests.get(f"{BASE}/user/tweets", params={"userName": h, "count": 25}, headers=H, timeout=40)
        if r.status_code != 200:
            print(f"\n### @{h} HTTP {r.status_code}"); continue
        d = r.json()
        tw = d.get("tweets", d if isinstance(d, list) else [])
        if not tw:
            print(f"\n### @{h} no tweets"); continue
        au = tw[0].get("author", {})
        bio = (au.get("description") or "").replace("\n", " ")[:200]
        print(f"\n### @{h}  | followers {au.get('followers')} | {au.get('location','')}")
        print(f"BIO: {bio}")
        flag = 0
        for t in tw:
            txt = " ".join((t.get("text") or "").split())
            low = txt.lower()
            if any(k in low for k in ("billion", "cinematic", "document", "vibe", "scaling", "scale")):
                print(f"  - {str(t.get('createdAt'))[:10]} | {txt[:220]}")
                flag += 1
            if flag >= 4:
                break
        print(f"  (has video: {sum(1 for t in tw if 'video' in json.dumps(t.get('extendedEntities') or {}))}/25)")
    except Exception as e:
        print(f"\n### @{h} ERR {str(e)[:80]}")
    time.sleep(0.3)
