feat(twitter): resolve reposts, expand t.co links and resume tweets pagination - #2518
Open
UncertaintyDeterminesYou4ndMe wants to merge 1 commit into
Conversation
… pagination `twitter tweets` gains three additive capabilities for backfilling a user timeline into a local archive: - `retweeted_tweet` column: a repost row only carries a truncated `"RT @user: …"` string and the reposter as author. The original post (full text, real author, media, counts, and its own `quoted_tweet`) is now surfaced from `legacy.retweeted_status_result` in the same shape as `quoted_tweet`. Tombstoned / unavailable originals yield `null`. - `--expand-urls`: replaces `https://t.co/…` links in `text` (and in the quoted / retweeted texts) with `expanded_url`, using `legacy.entities.urls`, the long-form `note_tweet` entity set, and the media entities. - `--cursor` / `--cursor-file`: resume pagination from a saved bottom cursor and persist the next one (empty file = timeline exhausted). With a cursor file, `--limit` becomes a soft target so whole pages are returned and no tweet falls between two runs. On a rate-limited first page the resume point is kept before the error is raised; a resumed run that finds no tail returns `[]` instead of `EmptyResultError`. Existing output stays byte-identical when the new flags are off (only the new `retweeted_tweet` column is appended). Helpers live in `shared.js` so other timeline adapters can reuse them.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Three additive capabilities for
opencli twitter tweets, motivated by backfilling a user's timeline (thousands of reposts) into a local Markdown archive:retweeted_tweetcolumn — a repost row only carries the truncated"RT @user: …"string, the reposter asauthor, and no media. The original post is now surfaced fromlegacy.retweeted_status_resultin the same shape as the existingquoted_tweet(id, author, name, full text, counts, created_at, url, media, and its ownquoted_tweet). Tombstoned / unavailable originals yieldnull;is_retweetis unchanged.--expand-urls(defaultfalse) — replaceshttps://t.co/…intext,quoted_tweet.textandretweeted_tweet.textwithexpanded_url, collected fromlegacy.entities.urls, the long-formnote_tweet … entity_set.urls(links in long posts are only listed there) and the media entities (the trailing t.co of attached photos/videos).--cursor/--cursor-file— resume pagination from a saved bottom cursor and persist the next one (empty file = timeline exhausted). Together with the existing--page-delaythis makes gentle, resumable backfills possible without re-fetching pages or tripping the 429 limiter. Details:--cursor-file,--limitbecomes a soft target: whole pages are returned so no tweet falls between two runs (cursors point at page boundaries);[]instead ofEmptyResultError.Output is unchanged when the new flags are off, apart from the appended
retweeted_tweetcolumn.collectTweetUrlMap,expandTweetUrlsandextractRetweetedTweetlive inshared.jssotimeline/search/list-tweetscan adopt them later.Related issue: —
Type of Change
Checklist
npx vitest run --project adapter clis/twitter/(560 passed) and the default gatenpm test; the only failures are 6 pre-existing ones insrc/cli.test.ts(browser tab targeting) that fail identically on an untouchedmaincheckout in my environment.tweets.test.js(expand-urls, retweeted_tweet, tombstone, cursor resume + cursor-file, rate-limited resume, empty resumed tail) andshared.test.js(helpers); usage example added todocs/adapters/browser/twitter.md;cli-manifest.jsonrebuilt.Documentation
CliErrorsubclasses instead of rawErrorScreenshots / Output
Live run against my own logged-in account (
--limit 5 --expand-urls true --cursor-file ./cur.txt -f json), one row abridged:{ "id": "2100136163877208198", "author": "snwkng50462474", "is_retweet": true, "text": "RT @AdrianPunk115: 本文分为上下两册,直接作为做网页动效的指南。 https://x.com/i/article/2098669987930210304", "retweeted_tweet": { "id": "2100136...", "author": "AdrianPunk115", "text": "本文分为上下两册,直接作为做网页动效的指南。 https://x.com/i/article/2098669987930210304", "url": "https://x.com/AdrianPunk115/status/...", "has_media": false } }./cur.txtafterwards holds the bottom cursor of the fetched page; a second run with--cursor "$(cat cur.txt)"continued from it, and reaching the end of the timeline left the file empty.