-
-
Save marckohlbrugge/93bcf631c3317e793f0295e6155e6e7f to your computer and use it in GitHub Desktop.
Requires jq. Simple command to work around X blocking bots. Returns LLM-friendly summary of a user account or post. Put in bin/ and optionally instruct Claude or your favorite LLM to use it when trying to fetch X links.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Fetch tweet or user profile in an LLM-friendly format using fxtwitter API | |
| set -e | |
| if [ -z "$1" ]; then | |
| echo "Usage: x <twitter-url-or-username>" | |
| echo "Examples:" | |
| echo " x https://x.com/marckohlbrugge/status/2005972157445333371" | |
| echo " x https://x.com/marckohlbrugge" | |
| echo " x @marckohlbrugge" | |
| echo " x marckohlbrugge" | |
| exit 1 | |
| fi | |
| input="$1" | |
| # Handle @username or plain username | |
| if [[ "$input" =~ ^@?([a-zA-Z0-9_]+)$ ]]; then | |
| username="${BASH_REMATCH[1]}" | |
| status_id="" | |
| # Extract username and optionally status ID from various Twitter URL formats | |
| elif [[ "$input" =~ (twitter\.com|x\.com)/([^/?]+)(/status/([0-9]+))? ]]; then | |
| username="${BASH_REMATCH[2]}" | |
| status_id="${BASH_REMATCH[4]}" | |
| else | |
| echo "Error: Invalid Twitter/X URL or username" | |
| exit 1 | |
| fi | |
| if [ -n "$status_id" ]; then | |
| # Fetch tweet | |
| api_url="https://api.fxtwitter.com/${username}/status/${status_id}" | |
| response=$(curl -s "$api_url") | |
| if ! echo "$response" | jq -e '.tweet' > /dev/null 2>&1; then | |
| echo "Error: Could not fetch tweet" | |
| echo "$response" | jq -r '.message // "Unknown error"' 2>/dev/null || echo "$response" | |
| exit 1 | |
| fi | |
| echo "$response" | jq -r ' | |
| .tweet | | |
| "**\(.author.name)** (@\(.author.screen_name)) · \(.created_at | split(" ") | [.[2], .[1], .[5]] | join(" "))", | |
| "Author: \(.author.followers) followers · \(.author.description | gsub("\n"; " "))", | |
| "", | |
| if .replying_to then "Replying to @\(.replying_to)\n" else "" end, | |
| "> \(.text | gsub("\n"; "\n> "))", | |
| "", | |
| if .media.photos then | |
| (.media.photos | map("Image: \(.url)") | join("\n")) | |
| else empty end, | |
| if .media.videos then | |
| (.media.videos | map("Video: \(.url)") | join("\n")) | |
| else empty end, | |
| "", | |
| "Likes: \(.likes) · Retweets: \(.retweets) · Replies: \(.replies) · Bookmarks: \(.bookmarks) · Views: \(.views)", | |
| if .community_note then "\nCommunity Note: \(.community_note)" else empty end | |
| ' | |
| else | |
| # Fetch user profile | |
| api_url="https://api.fxtwitter.com/${username}" | |
| response=$(curl -s "$api_url") | |
| if ! echo "$response" | jq -e '.user' > /dev/null 2>&1; then | |
| echo "Error: Could not fetch user" | |
| echo "$response" | jq -r '.message // "Unknown error"' 2>/dev/null || echo "$response" | |
| exit 1 | |
| fi | |
| echo "$response" | jq -r ' | |
| .user | | |
| "**\(.name)** (@\(.screen_name))" + (if .verification.verified then " ✓" else "" end), | |
| "Avatar: \(.avatar_url | gsub("_normal\\."; "_400x400."))", | |
| if .location and .location != "" then "Location: \(.location)" else empty end, | |
| if .about_account.based_in then "Based in: \(.about_account.based_in)" else empty end, | |
| if .website.display_url then "Website: \(.website.display_url)" else empty end, | |
| "Joined: \(.joined | split(" ") | [.[1], .[2], .[5]] | join(" "))", | |
| "", | |
| .description, | |
| "", | |
| "Followers: \(.followers) · Following: \(.following) · Tweets: \(.tweets) · Likes: \(.likes)" | |
| ' | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment