#!/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}"}
URL = "https://api.getxapi.com/twitter/tweet/advanced_search"

QUERIES = [
    ('X1_billion_app', '("will be worth billions" OR "billion dollar app" OR "app worth billions" OR "going to be huge" ) ("my app" OR "the app") since:2026-01-01'),
    ('X2_episode', '("episode 1" OR "ep. 1" OR "day 1 of") ("building" OR "vibe coding") ("app" OR "startup") filter:media since:2026-01-01'),
    ('X3_nonNative', '("vibe coding" OR "vibe coded") ("my english" OR "not a native" OR "in my accent") since:2026-01-01'),
]

for name, q in QUERIES:
    r = requests.get(URL, params={"q": q, "product": "Top"}, headers=H, timeout=45)
    if r.status_code != 200:
        print(f"[{name}] HTTP {r.status_code}"); continue
    tw = r.json().get("tweets", [])
    print(f"\n[{name}] {len(tw)}")
    for t in sorted(tw, key=lambda x: x.get("likeCount", 0) or 0, reverse=True)[:8]:
        a = (t.get("author") or {}).get("userName", "?")
        bio = ((t.get("author") or {}).get("description") or "").replace("\n", " ")[:70]
        txt = " ".join((t.get("text") or "").split())[:180]
        print(f"  @{a} | {t.get('likeCount')} | {str(t.get('createdAt'))[:10]}")
        print(f"    bio: {bio}")
        print(f"    {txt}")
    time.sleep(0.4)
