Skip to content

Commit c788835

Browse files
author
Wade
committed
add new struct
1 parent 033e860 commit c788835

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

timeline_rapidapi.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package twitterscraper
2+
3+
// timeline v2 JSON object
4+
type TimelineV2RapidAPI struct {
5+
Result struct {
6+
Timeline struct {
7+
Instructions []struct {
8+
Entries []entry `json:"entries"`
9+
Entry entry `json:"entry"`
10+
Type string `json:"type"`
11+
} `json:"instructions"`
12+
} `json:"timeline"`
13+
} `json:"result"`
14+
}
15+
16+
17+
func (timeline *TimelineV2RapidAPI) ParseTweets() ([]*Tweet, string) {
18+
var cursor string
19+
var tweets []*Tweet
20+
for _, instruction := range timeline.Result.Timeline.Instructions {
21+
22+
for _, entry := range instruction.Entries {
23+
if entry.Content.CursorType == "Bottom" {
24+
cursor = entry.Content.Value
25+
continue
26+
}
27+
if entry.Content.ItemContent.TweetResults.Result.Typename == "Tweet" || entry.Content.ItemContent.TweetResults.Result.Typename == "TweetWithVisibilityResults" {
28+
if tweet := entry.Content.ItemContent.TweetResults.Result.parse(); tweet != nil {
29+
tweets = append(tweets, tweet)
30+
}
31+
}
32+
if len(entry.Content.Items) > 0 {
33+
for _, item := range entry.Content.Items {
34+
if tweet := item.Item.ItemContent.TweetResults.Result.parse(); tweet != nil {
35+
tweets = append(tweets, tweet)
36+
}
37+
}
38+
}
39+
}
40+
}
41+
42+
return tweets, cursor
43+
}

0 commit comments

Comments
 (0)