forked from gaulliath/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
follower_to_screenname.go
80 lines (67 loc) · 1.79 KB
/
follower_to_screenname.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
package follower_to_screenName
import (
"net/url"
"os"
"strconv"
"github.com/ChimeraCoder/anaconda"
"github.com/jedib0t/go-pretty/table"
"github.com/Oni-kuki/operative-framework/session"
)
type FollowerScreenName struct {
session.SessionFilter
Sess *session.Session `json:"-"`
}
func PushFollowerScreenNameFilter(s *session.Session) *FollowerScreenName {
mod := FollowerScreenName{
Sess: s,
}
mod.AddModule("twitter.followers")
mod.AddModule("twitter.following")
return &mod
}
func (filter *FollowerScreenName) Name() string {
return "follower_to_screen"
}
func (filter *FollowerScreenName) Description() string {
return "Find screen name from twitter ID list"
}
func (filter *FollowerScreenName) Author() string {
return "Tristan Granier"
}
func (filter *FollowerScreenName) Start(mod session.Module) {
api := anaconda.NewTwitterApiWithCredentials(filter.Sess.Config.Twitter.Password, filter.Sess.Config.Twitter.Api.SKey, filter.Sess.Config.Twitter.Login, filter.Sess.Config.Twitter.Api.Key)
v := url.Values{}
trg, err := mod.GetParameter("TARGET")
if err != nil {
filter.Sess.Stream.Error(err.Error())
return
}
target, err := filter.Sess.GetTarget(trg.Value)
if err != nil {
filter.Sess.Stream.Error(err.Error())
return
}
t := filter.Sess.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{
"id",
"screen_name",
})
for _, id := range mod.GetResults() {
id64, err := strconv.ParseInt(id, 10, 64)
if err == nil {
user, errU := api.GetUsersShowById(id64, v)
if errU == nil {
t.AppendRow(table.Row{
id,
user.ScreenName,
})
result := target.NewResult()
result.Set("Twitter", user.ScreenName)
result.Set("ID", strconv.Itoa(int(user.Id)))
result.Save(mod, target)
}
}
}
filter.Sess.Stream.Render(t)
}