added analyze user followers

This commit is contained in:
arnaucode
2017-11-02 18:02:58 +01:00
parent 83d70e0b1c
commit 29814e88ac
9 changed files with 75 additions and 15 deletions

1
.gitignore vendored
View File

@@ -25,5 +25,6 @@ _testmain.go
twitterConfig.json
twitterConfig2.json
#build/twitterConfig.json
temp

BIN
argos

Binary file not shown.

19
askForUsername.go Normal file
View File

@@ -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
}

Binary file not shown.

7
error.go Normal file
View File

@@ -0,0 +1,7 @@
package main
func check(e error) {
if e != nil {
panic(e)
}
}

View File

@@ -67,6 +67,7 @@ func main() {
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 @@ option to select: `
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
@@ -106,6 +108,11 @@ option to select: `
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")
os.Exit(3)

View File

@@ -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)
}
}

View File

@@ -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)

View File

@@ -6,7 +6,6 @@ import (
"os"
"strconv"
"strings"
"time"
"github.com/dghubble/go-twitter/twitter"
)
@@ -40,9 +39,9 @@ func getFollowingUsers(client *twitter.Client, user *twitter.User) {
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) {