added analyze user followers
arnaucode arnaucode@gmail.com
Thu, 02 Nov 2017 18:02:58 +0100
9 files changed,
75 insertions(+),
15 deletions(-)
M
.gitignore
→
.gitignore
@@ -25,5 +25,6 @@ *.prof
twitterConfig.json +twitterConfig2.json #build/twitterConfig.json temp
A
askForUsername.go
@@ -0,0 +1,19 @@
+package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func askForUsername() string { + newcommand := bufio.NewReader(os.Stdin) + fmt.Print("enter username: @") + username, _ := newcommand.ReadString('\n') + username = strings.TrimSpace(username) + fmt.Print("user selected: ") + c.Cyan("@" + username) + fmt.Println("-----------------------") + return username +}
M
main.go
→
main.go
@@ -67,6 +67,7 @@ 4 - Delete Tweets
5 - Delete Favs (Likes) 6 - Tweet Random 7 - Analyze tweet + 8 - Analyze User Followers 0 - Exit script option to select: ` for {@@ -78,7 +79,8 @@
switch option { case "1": fmt.Println("selected 1 - Analyze username") - optionAnalyzeUserTweets(client) + username := askForUsername() + optionAnalyzeUserTweets(client, username) fmt.Println("") c.Purple("Note: the current hours displaying, are the Twitter servers hours (Coordinated Universal Time (UTC) +0000 UTC)") break@@ -105,6 +107,11 @@ break
case "7": fmt.Println("selected 7 - Analyze Tweet") optionAnalyzeTweet(client) + break + case "8": + fmt.Println("selected 8 - Analyze User Followers") + username := askForUsername() + optionAnalyzeUserFollowers(client, username) break case "0": fmt.Println("selected 0 - exit script")
A
optionAnalyzeUserFollowers.go
@@ -0,0 +1,37 @@
+package main + +import ( + "fmt" + + "github.com/dghubble/go-twitter/twitter" +) + +func optionAnalyzeUserFollowers(client *twitter.Client, username string) { + var followers []twitter.User + var maxid int64 + maxid = 0 + for i := 0; i < 4; i++ { + followersRaw, _, err := client.Followers.List(&twitter.FollowerListParams{ + ScreenName: username, + Count: 200, + Cursor: maxid, + }) + check(err) + maxid = followersRaw.NextCursor + for _, f := range followersRaw.Users { + /*fmt.Println("@" + follower.ScreenName) + fmt.Println("CreatedAt: " + follower.CreatedAt)*/ + followers = append(followers, f) + } + fmt.Println(followersRaw.NextCursor) + if followersRaw.NextCursor == 0 { + break + } + } + + for k, follower := range followers { + fmt.Print(k) + fmt.Println(" @" + follower.ScreenName) + fmt.Println(" CreatedAt: " + follower.CreatedAt) + } +}
M
optionAnalyzeUserTweets.go
→
optionAnalyzeUserTweets.go
@@ -1,23 +1,13 @@
package main import ( - "bufio" "fmt" - "os" "strconv" - "strings" "github.com/dghubble/go-twitter/twitter" ) -func optionAnalyzeUserTweets(client *twitter.Client) { - newcommand := bufio.NewReader(os.Stdin) - fmt.Print("enter username: @") - username, _ := newcommand.ReadString('\n') - username = strings.TrimSpace(username) - fmt.Print("user selected: ") - c.Cyan("@" + username) - fmt.Println("-----------------------") +func optionAnalyzeUserTweets(client *twitter.Client, username string) { //get tweets tweets := getTweets(client, username, iterationsCount)
M
optionUnfollowAll.go
→
optionUnfollowAll.go
@@ -6,7 +6,6 @@ "fmt"
"os" "strconv" "strings" - "time" "github.com/dghubble/go-twitter/twitter" )@@ -40,9 +39,9 @@ }
for _, k := range following.Users { unfollowUser(client, k.ScreenName) //wait to avoid the twitter api limitation - fmt.Println("waiting 1 min to avoid twitter api limitation") + /*fmt.Println("waiting 1 min to avoid twitter api limitation") fmt.Println(time.Now().Local()) - time.Sleep(1 * time.Minute) + time.Sleep(1 * time.Minute)*/ } } func optionUnfollowAll(client *twitter.Client) {