forked from n0madic/twitter-scraper
/
timeline_list.go
55 lines (52 loc) · 1.53 KB
/
timeline_list.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
44
45
46
47
48
49
50
51
52
53
54
55
package twitterscraper
type listEntry struct {
EntryId string `json:"entryId"`
SortIndex string `json:"sortIndex"`
Content struct {
CursorType string `json:"cursorType"`
EntryType string `json:"entryType"`
Value string `json:"value"`
Typename string `json:"__typename"`
ItemContent struct {
ItemType string `json:"itemType"`
Typename string `json:"__typename"`
TweetDisplayType string `json:"tweetDisplayType"`
TweetResults struct {
Result result `json:"result"`
} `json:"tweet_results"`
} `json:"itemContent"`
} `json:"content"`
}
type timelineForList struct {
Data struct {
List struct {
TweetsTimeline struct {
Timeline struct {
Instructions []struct {
Entries []listEntry `json:"entries"`
Entry listEntry `json:"entry"`
Type string `json:"type"`
} `json:"instructions"`
} `json:"timeline"`
} `json:"tweets_timeline"`
} `json:"list"`
} `json:"data"`
}
func (timeline *timelineForList) parseTweets() ([]*Tweet, string) {
var cursor string
var tweets []*Tweet
for _, instruction := range timeline.Data.List.TweetsTimeline.Timeline.Instructions {
for _, entry := range instruction.Entries {
if entry.Content.CursorType == "Top" {
cursor = entry.Content.Value
continue
}
if entry.Content.ItemContent.TweetResults.Result.Typename == "Tweet" {
if tweet := entry.Content.ItemContent.TweetResults.Result.parse(); tweet != nil {
tweets = append(tweets, tweet)
}
}
}
}
return tweets, cursor
}