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

def post_tweet(text: str) -> dict:
    """Post a new 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}
    
    response = requests.post(url, auth=auth, json=payload)
    return {"status": response.status_code, "response": response.json()}

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