File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments