diff --git a/build/argos b/build/argos index 71de4ea..77fb923 100755 Binary files a/build/argos and b/build/argos differ diff --git a/color.go b/color.go index 5c0dcc8..e945ac5 100644 --- a/color.go +++ b/color.go @@ -2,46 +2,54 @@ package main import "fmt" +//Color struct, defines the color type Color struct{} var c Color +//DarkGray color func (c Color) DarkGray(t string) { - fmt.Print("\x1b[30;1m") //red + fmt.Print("\x1b[30;1m") //dark gray fmt.Println(t) fmt.Print("\x1b[0m") //defaultColor } +//Red color func (c Color) Red(t string) { fmt.Print("\x1b[31;1m") //red fmt.Println(t) fmt.Print("\x1b[0m") //defaultColor } +//Green color func (c Color) Green(t string) { fmt.Print("\x1b[32;1m") //green fmt.Println(t) fmt.Print("\x1b[0m") //defaultColor } +//Yellow color func (c Color) Yellow(t string) { - fmt.Print("\x1b[33;1m") //green + fmt.Print("\x1b[33;1m") //yellow fmt.Println(t) fmt.Print("\x1b[0m") //defaultColor } +//Blue color func (c Color) Blue(t string) { fmt.Print("\x1b[34;1m") //blue fmt.Println(t) fmt.Print("\x1b[0m") //defaultColor } +//Purple color func (c Color) Purple(t string) { fmt.Print("\x1b[35;1m") //purple fmt.Println(t) fmt.Print("\x1b[0m") //defaultColor } +//Cyan color func (c Color) Cyan(t string) { fmt.Print("\x1b[36;1m") //cyan fmt.Println(t) diff --git a/getOperations.go b/getOperations.go new file mode 100644 index 0000000..d25bf36 --- /dev/null +++ b/getOperations.go @@ -0,0 +1,86 @@ +package main + +import ( + "fmt" + "strconv" + + "github.com/dghubble/go-twitter/twitter" +) + +func getTweets(client *twitter.Client, username string, iterations int) []twitter.Tweet { + var tweets []twitter.Tweet + var maxid int64 + for i := 0; i < iterations; i++ { + tweetsRaw, _, _ := client.Timelines.UserTimeline(&twitter.UserTimelineParams{ + ScreenName: username, + Count: 200, + MaxID: maxid, + }) + //if no tweets, stop getting tweets + if len(tweetsRaw) == 0 { + break + } + maxid = tweetsRaw[len(tweetsRaw)-1].ID + + for _, v := range tweetsRaw { + tweets = append(tweets, v) + } + } + + return tweets +} + +func getFavs(client *twitter.Client, username string, iterations int) []twitter.Tweet { + var tweets []twitter.Tweet + var maxid int64 + for i := 0; i < iterations; i++ { + tweetsRaw, _, _ := client.Favorites.List(&twitter.FavoriteListParams{ + ScreenName: username, + Count: 200, + MaxID: maxid, + }) + + //if no tweets, stop getting tweets + if len(tweetsRaw) == 0 { + break + } + maxid = tweetsRaw[len(tweetsRaw)-1].ID + + for _, v := range tweetsRaw { + tweets = append(tweets, v) + } + } + + return tweets +} + +func getUserData(client *twitter.Client) *twitter.User { + // Verify Credentials + verifyParams := &twitter.AccountVerifyParams{ + SkipStatus: twitter.Bool(true), + IncludeEmail: twitter.Bool(true), + } + user, _, _ := client.Accounts.VerifyCredentials(verifyParams) + return user +} + +func printUserData(user *twitter.User) { + fmt.Print("username: ") + c.Cyan(user.Name + " @" + user.ScreenName) + if user.Email != "" { + fmt.Print("Email ") + c.Red(user.Email) + } + if user.Location != "" { + fmt.Print("Location: ") + c.Red(user.Location) + } + fmt.Print("user created on: ") + c.Cyan(user.CreatedAt) + + fmt.Print("number of tweets: ") + c.Purple(strconv.Itoa(user.StatusesCount)) + + fmt.Print("number of favs: ") + c.Purple(strconv.Itoa(user.FavouritesCount)) +} diff --git a/main.go b/main.go index a5a4bd1..ecdc698 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,13 @@ func main() { fmt.Println("version " + version) fmt.Println("Reading twitterConfig.json file") client := readConfigTokensAndConnect() + fmt.Println("---------------") + fmt.Println("Getting user data...") + user := getUserData(client) + printUserData(user) + fmt.Println("") + newcommand := bufio.NewReader(os.Stdin) fmt.Print("Please select command number") options := ` @@ -29,7 +35,8 @@ func main() { 2 - Unfollow all 3 - Follow random 4 - Delete Tweets - 5 - Tweet Random + 5 - Delete Favs (Likes) + 6 - Tweet Random 0 - Exit script option to select: ` for { @@ -41,7 +48,7 @@ option to select: ` switch option { case "1": fmt.Println("selected 1 - Analyze username") - optionGetUserTweets(client) + optionAnalyzeUserTweets(client) break case "2": fmt.Println("selected 2 - Unfollow all") @@ -56,6 +63,10 @@ option to select: ` optionDeleteTweets(client) break case "5": + fmt.Println("selected 5 - Delete Favs (Likes)") + optionDeleteFavs(client) + break + case "6": fmt.Println("selected 5 - Tweet random") optionTweetRandom(client) break diff --git a/optionGetUserTweets.go b/optionAnalyzeUserTweets.go similarity index 75% rename from optionGetUserTweets.go rename to optionAnalyzeUserTweets.go index e81b3c8..4084378 100644 --- a/optionGetUserTweets.go +++ b/optionAnalyzeUserTweets.go @@ -10,29 +10,7 @@ import ( "github.com/dghubble/go-twitter/twitter" ) -func getTweets(client *twitter.Client, username string, iterations int) []twitter.Tweet { - var tweets []twitter.Tweet - var maxid int64 - for i := 0; i < iterations; i++ { - tweetsRaw, _, _ := client.Timelines.UserTimeline(&twitter.UserTimelineParams{ - ScreenName: username, - Count: 200, - MaxID: maxid, - }) - //if no tweets, stop getting tweets - if len(tweetsRaw) == 0 { - break - } - maxid = tweetsRaw[len(tweetsRaw)-1].ID - - for _, v := range tweetsRaw { - tweets = append(tweets, v) - } - } - - return tweets -} -func optionGetUserTweets(client *twitter.Client) { +func optionAnalyzeUserTweets(client *twitter.Client) { newcommand := bufio.NewReader(os.Stdin) fmt.Print("enter username: @") username, _ := newcommand.ReadString('\n') diff --git a/optionDeleteFavs.go b/optionDeleteFavs.go new file mode 100644 index 0000000..17c7c66 --- /dev/null +++ b/optionDeleteFavs.go @@ -0,0 +1,44 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" + + "github.com/dghubble/go-twitter/twitter" +) + +func deleteFavs(client *twitter.Client, user *twitter.User) { + tweets := getFavs(client, user.ScreenName, iterationsCount) + count := 0 + for _, v := range tweets { + c.Red("deleting: [id: " + v.IDStr + "] " + v.Text) + deleted, _, _ := client.Favorites.Destroy(&twitter.FavoriteDestroyParams{ + ID: v.ID, + }) + c.Green("DELETED: [id: " + deleted.IDStr + "] " + deleted.Text) + count++ + } + c.Red("Deleted " + strconv.Itoa(count) + " favs") +} + +func optionDeleteFavs(client *twitter.Client) { + c.Red("Are you sure you want to delete your favs? [y/n]") + newcommand := bufio.NewReader(os.Stdin) + answer, _ := newcommand.ReadString('\n') + answer = strings.TrimSpace(answer) + switch answer { + case "y": + fmt.Println("ok, you are sure") + user := getUserData(client) + deleteFavs(client, user) + user = getUserData(client) + printUserData(user) + break + default: + fmt.Println("Operation cancelled") + break + } +} diff --git a/optionDeleteTweets.go b/optionDeleteTweets.go index 7f4f8b4..8de807c 100644 --- a/optionDeleteTweets.go +++ b/optionDeleteTweets.go @@ -10,32 +10,6 @@ import ( "github.com/dghubble/go-twitter/twitter" ) -func getUserData(client *twitter.Client) *twitter.User { - // Verify Credentials - verifyParams := &twitter.AccountVerifyParams{ - SkipStatus: twitter.Bool(true), - IncludeEmail: twitter.Bool(true), - } - user, _, _ := client.Accounts.VerifyCredentials(verifyParams) - return user -} -func printUserData(user *twitter.User) { - fmt.Print("username: ") - c.Cyan(user.Name + " @" + user.ScreenName) - if user.Email != "" { - fmt.Print("Email ") - c.Red(user.Email) - } - if user.Location != "" { - fmt.Print("Location: ") - c.Red(user.Location) - } - fmt.Print("user created on: ") - c.Cyan(user.CreatedAt) - - fmt.Print("number of tweets: ") - c.Purple(strconv.Itoa(user.StatusesCount)) -} func deleteTweets(client *twitter.Client, user *twitter.User) { tweets := getTweets(client, user.ScreenName, iterationsCount) count := 0 @@ -52,7 +26,7 @@ func optionDeleteTweets(client *twitter.Client) { user := getUserData(client) printUserData(user) fmt.Println("") - c.Red("Are you sure you want to delete you tweets? [y/n]") + c.Red("Are you sure you want to delete your tweets? [y/n]") newcommand := bufio.NewReader(os.Stdin) answer, _ := newcommand.ReadString('\n') answer = strings.TrimSpace(answer) diff --git a/readConfigTokensAndConnect.go b/readConfigTokensAndConnect.go index aca0820..9b4606a 100644 --- a/readConfigTokensAndConnect.go +++ b/readConfigTokensAndConnect.go @@ -9,6 +9,7 @@ import ( "github.com/dghubble/oauth1" ) +//Config stores the data from json twitterConfig.json file type Config struct { Consumer_key string `json:"consumer_key"` Consumer_secret string `json:"consumer_secret"`