feat: detect subscriber-only tweets via tweetInterstitial (#33)
Extract visibility metadata from TweetWithVisibilityResults wrapper before unwrapping. Adds is_subscriber_only field to Tweet model, with full serialization roundtrip and test coverage. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,7 @@ def tweet_factory():
|
||||
score=overrides.pop("score", 0.0),
|
||||
article_title=overrides.pop("article_title", None),
|
||||
article_text=overrides.pop("article_text", None),
|
||||
is_subscriber_only=overrides.pop("is_subscriber_only", False),
|
||||
)
|
||||
|
||||
return _make_tweet
|
||||
|
||||
4
tests/fixtures/list_timeline.json
vendored
4
tests/fixtures/list_timeline.json
vendored
@@ -15,6 +15,10 @@
|
||||
"tweet_results": {
|
||||
"result": {
|
||||
"__typename": "TweetWithVisibilityResults",
|
||||
"tweetInterstitial": {
|
||||
"__typename": "TweetInterstitial",
|
||||
"text": { "rtl": false, "text": "Subscribe to @lister to see this post" }
|
||||
},
|
||||
"tweet": {
|
||||
"__typename": "Tweet",
|
||||
"rest_id": "700",
|
||||
|
||||
@@ -641,6 +641,7 @@ class TestParseTweetResult:
|
||||
tweet = parse_tweet_result(wrapped)
|
||||
assert tweet is not None
|
||||
assert tweet.id == "1234567890"
|
||||
assert tweet.is_subscriber_only is False
|
||||
|
||||
@patch("twitter_cli.client._get_cffi_session")
|
||||
@patch("twitter_cli.client._gen_ct_headers", return_value={})
|
||||
|
||||
@@ -74,6 +74,7 @@ def test_parse_list_timeline_fixture_with_visibility_wrapper(fixture_loader) ->
|
||||
assert cursor == "list-cursor"
|
||||
assert tweets[0].author.verified is True
|
||||
assert tweets[0].lang == "zh"
|
||||
assert tweets[0].is_subscriber_only is True
|
||||
|
||||
|
||||
def test_fetch_user_list_with_fixture(monkeypatch, fixture_loader) -> None:
|
||||
|
||||
@@ -77,3 +77,11 @@ def test_tweet_roundtrip_preserves_article_fields(tweet_factory) -> None:
|
||||
|
||||
assert restored.article_title == "Long-form title"
|
||||
assert restored.article_text == "Intro\n\n## Details"
|
||||
|
||||
|
||||
def test_tweet_roundtrip_preserves_subscriber_only(tweet_factory) -> None:
|
||||
tweet = tweet_factory("99", is_subscriber_only=True)
|
||||
payload = tweet_to_dict(tweet)
|
||||
assert payload["isSubscriberOnly"] is True
|
||||
restored = tweet_from_dict(payload)
|
||||
assert restored.is_subscriber_only is True
|
||||
|
||||
Reference in New Issue
Block a user