Browse Source

started implementation of functionallity to delete tweets, implemented better colors println

master
arnaucode 7 years ago
parent
commit
19b11221bc
4 changed files with 111 additions and 7 deletions
  1. +37
    -0
      color.go
  2. +66
    -0
      deleteTweetsAndFavs.go
  3. +5
    -3
      getUserTweets.go
  4. +3
    -4
      main.go

+ 37
- 0
color.go

@ -0,0 +1,37 @@
package main
import "fmt"
type Color struct{}
var c Color
func (c Color) Cyan(t string) {
fmt.Print("\x1b[36;1m") //cyan
fmt.Println(t)
fmt.Print("\x1b[0m") //defaultColor
}
func (c Color) Red(t string) {
fmt.Print("\x1b[31;1m") //red
fmt.Println(t)
fmt.Print("\x1b[0m") //defaultColor
}
func (c Color) Green(t string) {
fmt.Print("\x1b[32;1m") //green
fmt.Println(t)
fmt.Print("\x1b[0m") //defaultColor
}
func (c Color) Blue(t string) {
fmt.Print("\x1b[34;1m") //blue
fmt.Println(t)
fmt.Print("\x1b[0m") //defaultColor
}
func (c Color) Purple(t string) {
fmt.Print("\x1b[35;1m") //purple
fmt.Println(t)
fmt.Print("\x1b[0m") //defaultColor
}

+ 66
- 0
deleteTweetsAndFavs.go

@ -0,0 +1,66 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"github.com/dghubble/go-twitter/twitter"
)
func getAndPrintUserData(client *twitter.Client) *twitter.User {
// Verify Credentials
verifyParams := &twitter.AccountVerifyParams{
SkipStatus: twitter.Bool(true),
IncludeEmail: twitter.Bool(true),
}
user, _, _ := client.Accounts.VerifyCredentials(verifyParams)
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)
}
c.Cyan("user created on: " + user.CreatedAt)
fmt.Print("number of tweets: ")
c.Purple(strconv.Itoa(user.StatusesCount))
return user
}
func deleteTweets(client *twitter.Client, user *twitter.User) {
tweets := getTweets(client, user.ScreenName, iterationsCount)
for _, v := range tweets {
c.Red("deleting: [id: " + v.IDStr + "] " + v.Text)
deleted, _, _ := client.Statuses.Destroy(v.ID, nil)
c.Green("deleting: [id: " + deleted.IDStr + "] " + deleted.Text)
}
}
func deleteFavs(client *twitter.Client) {
}
func deleteTweetsAndFavs(client *twitter.Client) {
fmt.Println("Getting user data...")
user := getAndPrintUserData(client)
fmt.Println("")
fmt.Println("Are you sure you want to delete you tweets? [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")
deleteTweets(client, user)
deleteFavs(client)
user = getAndPrintUserData(client)
break
default:
fmt.Println("Operation cancelled")
break
}
}

+ 5
- 3
getUserTweets.go

@ -37,8 +37,8 @@ func getUserTweets(client *twitter.Client) {
fmt.Print("enter username: @")
username, _ := newcommand.ReadString('\n')
username = strings.TrimSpace(username)
fmt.Println("user selected: \x1b[36;1m@" + username)
fmt.Print("\x1b[0m") //defaultColor
fmt.Print("user selected: ")
c.Cyan("@" + username)
fmt.Println("-----------------------")
//get tweets
@ -77,5 +77,7 @@ func getUserTweets(client *twitter.Client) {
fmt.Println(" ")
fmt.Println("Total of " + strconv.Itoa(len(tweets)) + " tweets analyzed")
fmt.Println(" ")
fmt.Println("User @" + username + " analysis finished")
fmt.Print("User @")
c.Cyan(username)
fmt.Println(" analysis finished")
}

+ 3
- 4
main.go

@ -27,6 +27,7 @@ func main() {
fmt.Print("Please select command number")
options := `
1 - Analyze username
2 - Delete Tweets
0 - Exit script
option to select: `
for {
@ -41,10 +42,8 @@ option to select: `
getUserTweets(client)
break
case "2":
fmt.Println("selected 2 - Delete all Favs")
break
case "3":
fmt.Println("selected 3 - Delete all Tweets and Favs")
fmt.Println("selected 2 - Delete Tweets")
deleteTweetsAndFavs(client)
break
case "0":
fmt.Println("selected 0 - exit script")

Loading…
Cancel
Save