#!/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 = ["bymarcoperez", "omarontape", "Cedric_Roberge", "DavidOndrej1", "albysjourney", "samuelgerges__"]

for h in HANDLES:
    r = requests.get(f"{BASE}/user/tweets", params={"userName": h, "count": 40}, headers=H, timeout=40)
    if r.status_code != 200:
        print(f"\n### @{h} HTTP {r.status_code}"); time.sleep(0.3); continue
    tw = r.json().get("tweets", [])
    if not tw:
        print(f"\n### @{h} EMPTY (suspended or none)"); time.sleep(0.3); continue
    au = tw[0].get("author", {})
    print(f"\n### @{h} | followers {au.get('followers')} | tweets {au.get('statusesCount')} | loc {au.get('location','')}")
    print(f"BIO: {((au.get('description') or '')).replace(chr(10),' ')[:160]}")
    vids = 0
    for t in tw:
        blob = json.dumps(t.get("extendedEntities") or {}) + json.dumps(t.get("entities") or {})
        if '"type": "video"' in blob or "video_info" in blob or "/video/" in blob:
            vids += 1
    print(f"video posts in last {len(tw)}: {vids}")
    for t in tw[:6]:
        txt = " ".join((t.get("text") or "").split())[:180]
        print(f"  - {str(t.get('createdAt'))[:10]} | {txt}")
    time.sleep(0.3)
