Skip to content

feat: add twitter article command for long-form Twitter Articles#15

Open
Catafal wants to merge 1 commit intojackwener:mainfrom
Catafal:feat/article-command
Open

feat: add twitter article command for long-form Twitter Articles#15
Catafal wants to merge 1 commit intojackwener:mainfrom
Catafal:feat/article-command

Conversation

@Catafal
Copy link

@Catafal Catafal commented Mar 11, 2026

Summary

  • Adds twitter article <id|url> command to fetch and display Twitter Articles (long-form posts, distinct from regular tweets)
  • Article body is retrieved via the TweetResultByRestId GraphQL endpoint (lighter than TweetDetail — no replies timeline) with the withArticlePlainText=True field toggle, which is required for the API to include the article body
  • Draft.js content blocks are converted to Markdown by _parse_article() in parser.py, then rendered in the terminal using rich.Markdown
  • Accepts both numeric IDs and full URLs (/article/<id> and /status/<id> patterns both supported)
  • Supports --json, --yaml, and --compact output modes consistently with all other read commands
  • articleTitle and articleText fields are included in the standard tweet JSON/YAML output envelope

Files changed

File Change
twitter_cli/graphql.py Add TweetResultByRestId queryId
twitter_cli/client.py Add fetch_article() method
twitter_cli/formatter.py Add print_article() with rich Panel + Markdown rendering
twitter_cli/cli.py Add article command; extend URL regex to accept /article/ paths
README.md Document new command in Features + Usage (EN + ZH)
SCHEMA.md Document articleTitle / articleText output fields
SKILL.md Add to Command Reference, agent workflow example, Limitations

Test plan

  • twitter article <numeric-id> fetches and renders a known article
  • twitter article <full-article-url> (e.g. https://x.com/user/article/123) resolves correctly
  • twitter article <id> --json returns envelope with articleTitle and articleText under data
  • twitter article <regular-tweet-id> returns a clear not_found error (tweet has no article content)
  • twitter article --help shows correct usage

🤖 Generated with Claude Code

Adds `twitter article <id|url>` to read Twitter Articles (long-form posts)
from the CLI. The article body is fetched via the TweetResultByRestId
GraphQL endpoint and rendered as Markdown in the terminal using rich.

Changes:
- graphql.py: add TweetResultByRestId queryId to FALLBACK_QUERY_IDS
- client.py: add fetch_article() using withArticlePlainText=True field toggle
  (required — omitting it silently drops the article body from the API response)
- parser.py: _parse_article() converts draft.js content blocks to Markdown;
  parse_tweet_result() already calls it, populating Tweet.article_title/text
- models.py + serialization.py: article_title/article_text fields already
  present and serialized/deserialized correctly
- formatter.py: add print_article() — meta Panel (author, stats, link) +
  rich.Markdown body rendered below to avoid panel line-length constraints
- cli.py: add `article` command with --json/--yaml/--compact support;
  extend _normalize_tweet_id() regex to accept /article/<id> URLs in
  addition to the existing /status/<id> pattern
- README.md, SCHEMA.md, SKILL.md: document the new command, article-specific
  output fields, URL format, and agent workflow examples (EN + ZH)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant