BUGFIX: fix a scraping error on encountering a 'composer' entry in a tweet thread

This commit is contained in:
Alessio 2025-02-02 17:28:18 -08:00
parent a3ddfa72b7
commit cd02110021
4 changed files with 12 additions and 6 deletions

View File

@ -710,6 +710,10 @@ func (api_response APIV2Response) ToTweetTrove() (TweetTrove, error) {
} }
// Infer "in_reply_to_id" for tombstoned tweets from the order of entries, if applicable // Infer "in_reply_to_id" for tombstoned tweets from the order of entries, if applicable
if entry.Content.EntryType == "TimelineTimelineItem" { if entry.Content.EntryType == "TimelineTimelineItem" {
if strings.HasPrefix(entry.EntryID, "tweetcomposer") {
// Skip composer
continue
}
entry_type, main_tweet_id := entry.ParseID() entry_type, main_tweet_id := entry.ParseID()
if entry_type == "cursor-showmorethreadsprompt" || if entry_type == "cursor-showmorethreadsprompt" ||
entry_type == "cursor-bottom" || entry_type == "cursor-bottom" ||

View File

@ -1001,12 +1001,14 @@ func TestNoFailOnComposerEntryInTimelineModule(t *testing.T) {
func TestNoFailOnComposerEntryInRegularThread(t *testing.T) { func TestNoFailOnComposerEntryInRegularThread(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
require := require.New(t) require := require.New(t)
data, err := os.ReadFile("test_responses/api_v2/composer_entry_item_non_module.json") data, err := os.ReadFile("test_responses/api_v2/composer_entry_full_thread.json")
require.NoError(err) require.NoError(err)
var entry_result APIV2Entry var api_response APIV2Response
err = json.Unmarshal(data, &entry_result) err = json.Unmarshal(data, &api_response)
require.NoError(err) require.NoError(err)
trove := entry_result.ToTweetTrove() trove, err := api_response.ToTweetTrove()
assert.Len(trove.Tweets, 0) require.NoError(err)
assert.Len(trove.Tweets, 3)
} }

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"entryId":"tweetcomposer--1","sortIndex":"7407168758699622302","content":{"entryType":"TimelineTimelineItem","__typename":"TimelineTimelineItem","itemContent":{"itemType":"TimelineTweetComposer","__typename":"TimelineTweetComposer","composerDisplayType":"SelfThread","composerButtonText":"Add another post","composerButtonUrl":{"url":"twitter://post?in_reply_to_status_id=1816203278155153495","urlType":"DeepLink"}}}}