/
twitter.go
158 lines (148 loc) · 4.61 KB
/
twitter.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package source
import (
"os"
"github.com/elchead/misou/filesystem"
"github.com/elchead/misou/search"
)
const twitterProvider = "twitter"
const twitterUrl = "https://twitter.com/astobbe_/status/"
type TwitterParser struct {
File *os.File
}
type tweet struct {
CreatedAt string `json:"created_at"`
DisplayTextRange []string `json:"display_text_range"`
Entities struct {
Hashtags []interface{} `json:"hashtags"`
Media []struct {
DisplayURL string `json:"display_url"`
ExpandedURL string `json:"expanded_url"`
ID string `json:"id"`
IdStr string `json:"id_str"`
Indices []string `json:"indices"`
MediaURL string `json:"media_url"`
MediaUrlHttps string `json:"media_url_https"`
Sizes struct {
Large struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"large"`
Medium struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"medium"`
Small struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"small"`
Thumb struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"thumb"`
} `json:"sizes"`
SourceStatusID string `json:"source_status_id"`
SourceStatusIdStr string `json:"source_status_id_str"`
SourceUserID string `json:"source_user_id"`
SourceUserIdStr string `json:"source_user_id_str"`
Type string `json:"type"`
URL string `json:"url"`
} `json:"media"`
Symbols []interface{} `json:"symbols"`
Urls []interface{} `json:"urls"`
UserMentions []struct {
ID string `json:"id"`
IdStr string `json:"id_str"`
Indices []string `json:"indices"`
Name string `json:"name"`
ScreenName string `json:"screen_name"`
} `json:"user_mentions"`
} `json:"entities"`
ExtendedEntities struct {
Media []struct {
DisplayURL string `json:"display_url"`
ExpandedURL string `json:"expanded_url"`
ID string `json:"id"`
IdStr string `json:"id_str"`
Indices []string `json:"indices"`
MediaURL string `json:"media_url"`
MediaUrlHttps string `json:"media_url_https"`
Sizes struct {
Large struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"large"`
Medium struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"medium"`
Small struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"small"`
Thumb struct {
H string `json:"h"`
Resize string `json:"resize"`
W string `json:"w"`
} `json:"thumb"`
} `json:"sizes"`
SourceStatusID string `json:"source_status_id"`
SourceStatusIdStr string `json:"source_status_id_str"`
SourceUserID string `json:"source_user_id"`
SourceUserIdStr string `json:"source_user_id_str"`
Type string `json:"type"`
URL string `json:"url"`
} `json:"media"`
} `json:"extended_entities"`
FavoriteCount string `json:"favorite_count"`
Favorited bool `json:"favorited"`
FullText string `json:"full_text"`
ID string `json:"id"`
IdStr string `json:"id_str"`
Lang string `json:"lang"`
PossiblySensitive bool `json:"possibly_sensitive"`
RetweetCount string `json:"retweet_count"`
Retweeted bool `json:"retweeted"`
Source string `json:"source"`
Truncated bool `json:"truncated"`
}
type twitterEntry struct {
Tweet tweet `json:"tweet"`
}
func (t TwitterParser) TransformToData() ([]*search.IndexData,error) {
var entries []twitterEntry
err := filesystem.LoadVariable(t.File,&entries)
if err != nil {
return []*search.IndexData{},err
}
// fmt.Println(entries)
// return []*search.IndexData{},nil
var indexData []*search.IndexData
for _, entry := range entries {
data := entry.Tweet
// fmt.Println(t.transformTweet(data))
indexData = append(indexData,t.transformTweet(data))
}
return indexData,nil
}
func (t TwitterParser) transformTweet(data tweet) *search.IndexData {
var url string
if len(data.Entities.Media) > 0 {
url = data.Entities.Media[0].URL
} else {
url = twitterUrl + data.ID
}
content := data.FullText
return &search.IndexData{
Title: "",
Link: url,
Content: content,
Provider: twitterProvider,
}
}