forked from gaulliath/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter_geo_tweet.go
120 lines (105 loc) · 2.59 KB
/
twitter_geo_tweet.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
package twitter
import (
"github.com/ChimeraCoder/anaconda"
"github.com/graniet/go-pretty/table"
"github.com/Oni-kuki/operative-framework/session"
"net/url"
"os"
)
type TwitterGeoTweet struct {
session.SessionModule
Sess *session.Session `json:"-"`
}
func PushTwitterGeoTweetModule(s *session.Session) *TwitterGeoTweet {
mod := TwitterGeoTweet{
Sess: s,
}
mod.CreateNewParam("TARGET", "TWITTER POST ID", "", true, session.STRING)
return &mod
}
func (module *TwitterGeoTweet) Name() string {
return "twitter.geo.search"
}
func (module *TwitterGeoTweet) Description() string {
return "Show geolocation information of selected tweet"
}
func (module *TwitterGeoTweet) Author() string {
return "Tristan Granier"
}
func (module *TwitterGeoTweet) GetType() []string {
return []string{
session.T_TARGET_TEXT,
}
}
func (module *TwitterGeoTweet) GetInformation() session.ModuleInformation {
information := session.ModuleInformation{
Name: module.Name(),
Description: module.Description(),
Author: module.Author(),
Type: module.GetType(),
Parameters: module.Parameters,
}
return information
}
func (module *TwitterGeoTweet) Start() {
trg, err := module.GetParameter("TARGET")
if err != nil {
module.Sess.Stream.Error(err.Error())
return
}
target, err := module.Sess.GetTarget(trg.Value)
if err != nil {
module.Sess.Stream.Error(err.Error())
return
}
api := anaconda.NewTwitterApiWithCredentials(module.Sess.Config.Twitter.Password, module.Sess.Config.Twitter.Api.SKey, module.Sess.Config.Twitter.Login, module.Sess.Config.Twitter.Api.Key)
v := url.Values{}
var ids []int64
ids = append(ids, module.Sess.StringToInt64(target.GetName()))
search, err := api.GetTweetsLookupByIds(ids, v)
if err != nil {
module.Sess.Stream.Error(err.Error())
return
}
t := module.Sess.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
for _, tweet := range search {
if tweet.Id == module.Sess.StringToInt64(target.GetName()) {
latitude, _ := tweet.Latitude()
longitude, _ := tweet.Longitude()
t.AppendRow(table.Row{
"ID",
tweet.Id,
})
t.AppendRow(table.Row{
"Text",
tweet.Text,
})
t.AppendRow(table.Row{
"Place Name",
tweet.Place.FullName,
})
t.AppendRow(table.Row{
"Place Type",
tweet.Place.PlaceType,
})
t.AppendRow(table.Row{
"Place Country",
tweet.Place.Country,
})
t.AppendRow(table.Row{
"Place URL",
tweet.Place.URL,
})
t.AppendRow(table.Row{
"Latitude",
latitude,
})
t.AppendRow(table.Row{
"Longitude",
longitude,
})
}
}
module.Sess.Stream.Render(t)
}