#!/usr/bin/env python3 # /// script # requires-python = ">=3.11" # dependencies = ["requests"] # /// """Upload a file to S2 storage at s2.connorrhodes.com. Usage: s2_upload.py [--delete] Options: --delete Delete the local file after a successful upload. Output: Prints the S2 URL on stdout. """ import sys import os import requests API_KEY = "LT6CXiLT5cEApfqtThz17bENr6OLP804FepOMqa1tZkfTGXiiCcSFlupl6gaYeX" ENDPOINT = "https://api.connorrhodes.com/agent/s2_upload" def main(): args = sys.argv[1:] if not args or args[0] in ("-h", "--help"): print(__doc__) sys.exit(0 if args else 1) file_path = args[0] delete_after = "--delete" in args if not os.path.isfile(file_path): print(f"Error: file not found: {file_path}", file=sys.stderr) sys.exit(1) with open(file_path, "rb") as f: resp = requests.post( ENDPOINT, headers={"x-api-key": API_KEY}, files={"file": (os.path.basename(file_path), f)}, ) resp.raise_for_status() url = resp.json() if isinstance(resp.json(), str) else resp.text.strip().strip('"') print(url) if delete_after: os.remove(file_path) if __name__ == "__main__": main()