-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeline_rapidapi.go
43 lines (38 loc) · 1.18 KB
/
timeline_rapidapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package twitterscraper
// timeline v2 JSON object
type TimelineV2RapidAPI struct {
Result struct {
Timeline struct {
Instructions []struct {
Entries []entry `json:"entries"`
Entry entry `json:"entry"`
Type string `json:"type"`
} `json:"instructions"`
} `json:"timeline"`
} `json:"result"`
}
func (timeline *TimelineV2RapidAPI) ParseTweets() ([]*Tweet, string) {
var cursor string
var tweets []*Tweet
for _, instruction := range timeline.Result.Timeline.Instructions {
for _, entry := range instruction.Entries {
if entry.Content.CursorType == "Bottom" {
cursor = entry.Content.Value
continue
}
if entry.Content.ItemContent.TweetResults.Result.Typename == "Tweet" || entry.Content.ItemContent.TweetResults.Result.Typename == "TweetWithVisibilityResults" {
if tweet := entry.Content.ItemContent.TweetResults.Result.parse(); tweet != nil {
tweets = append(tweets, tweet)
}
}
if len(entry.Content.Items) > 0 {
for _, item := range entry.Content.Items {
if tweet := item.Item.ItemContent.TweetResults.Result.parse(); tweet != nil {
tweets = append(tweets, tweet)
}
}
}
}
}
return tweets, cursor
}