BUGFIX: fix a scraping error on encountering a 'composer' entry in a tweet thread
This commit is contained in:
parent
a3ddfa72b7
commit
cd02110021
@ -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
|
||||
if entry.Content.EntryType == "TimelineTimelineItem" {
|
||||
if strings.HasPrefix(entry.EntryID, "tweetcomposer") {
|
||||
// Skip composer
|
||||
continue
|
||||
}
|
||||
entry_type, main_tweet_id := entry.ParseID()
|
||||
if entry_type == "cursor-showmorethreadsprompt" ||
|
||||
entry_type == "cursor-bottom" ||
|
||||
|
@ -1001,12 +1001,14 @@ func TestNoFailOnComposerEntryInTimelineModule(t *testing.T) {
|
||||
func TestNoFailOnComposerEntryInRegularThread(t *testing.T) {
|
||||
assert := assert.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)
|
||||
var entry_result APIV2Entry
|
||||
err = json.Unmarshal(data, &entry_result)
|
||||
var api_response APIV2Response
|
||||
err = json.Unmarshal(data, &api_response)
|
||||
require.NoError(err)
|
||||
|
||||
trove := entry_result.ToTweetTrove()
|
||||
assert.Len(trove.Tweets, 0)
|
||||
trove, err := api_response.ToTweetTrove()
|
||||
require.NoError(err)
|
||||
|
||||
assert.Len(trove.Tweets, 3)
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -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"}}}}
|
Loading…
x
Reference in New Issue
Block a user