#!/usr/bin/env python3
"""Post a reply to a tweet"""
import json
import sys
import requests
from requests_oauthlib import OAuth1

def post_reply(tweet_id: str, text: str) -> dict:
    """Post a reply to a specific tweet"""
    with open('/home/clawd/secrets/twitter/credentials.json') as f:
        creds = json.load(f)
    
    oauth1 = creds['oauth1']
    auth = OAuth1(
        oauth1['consumer_key'],
        oauth1['consumer_secret'],
        oauth1['access_token'],
        oauth1['access_token_secret']
    )
    
    url = "https://api.twitter.com/2/tweets"
    payload = {
        "text": text,
        "reply": {
            "in_reply_to_tweet_id": tweet_id
        }
    }
    
    response = requests.post(url, auth=auth, json=payload)
    return {"status": response.status_code, "response": response.json()}

if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("Usage: twitter_reply.py <tweet_id> <text>")
        sys.exit(1)
    
    tweet_id = sys.argv[1]
    text = sys.argv[2]
    result = post_reply(tweet_id, text)
    print(json.dumps(result, indent=2))
