unfollowAll (count 200), and followRandom implemented. But twitter api blocks after few petitions

This commit is contained in:
arnaucode
2017-04-19 01:32:49 +02:00
parent a86377a594
commit 154968d81d
3 changed files with 45 additions and 14 deletions

View File

@@ -39,7 +39,7 @@ func printUserData(user *twitter.User) {
func deleteTweets(client *twitter.Client, user *twitter.User) { func deleteTweets(client *twitter.Client, user *twitter.User) {
tweets := getTweets(client, user.ScreenName, iterationsCount) tweets := getTweets(client, user.ScreenName, iterationsCount)
count := 0 count := 0
fmt.Println(tweets) //fmt.Println(tweets)
for _, v := range tweets { for _, v := range tweets {
c.Red("deleting: [id: " + v.IDStr + "] " + v.Text) c.Red("deleting: [id: " + v.IDStr + "] " + v.Text)
deleted, _, _ := client.Statuses.Destroy(v.ID, nil) deleted, _, _ := client.Statuses.Destroy(v.ID, nil)

View File

@@ -14,21 +14,35 @@ import (
}*/ }*/
func getUserFollower(client *twitter.Client) string { func getUserToFollowFromUser(client *twitter.Client, fromUser string) string {
ScreenName := "username" friends, httpResp, err := client.Friends.List(&twitter.FriendListParams{
return ScreenName ScreenName: fromUser,
Count: 1,
})
if err != nil {
fmt.Println(err)
}
if httpResp.Status != "200 OK" {
c.Red(httpResp.Status)
}
//fmt.Println(friends.Users)
c.Green(friends.Users[0].ScreenName)
return friends.Users[0].ScreenName
} }
func followUser(client *twitter.Client, ScreenName string) { func followUser(client *twitter.Client, screenName string) {
_, _, _ = client.Friendships.Create(&twitter.FriendshipCreateParams{
ScreenName: screenName,
})
} }
func followRandom(client *twitter.Client, nFollow int, ScreenName string) { func followRandom(client *twitter.Client, nFollow int, screenName string) {
fmt.Println("Starting to follow " + strconv.Itoa(nFollow) + " users") fmt.Println("Starting to follow " + strconv.Itoa(nFollow) + " users")
//screenName := firstScreenName
for i := 0; i < nFollow; i++ { for i := 0; i < nFollow; i++ {
ScreenName = getUserFollower(client) userToFollow := getUserToFollowFromUser(client, screenName)
followUser(client, ScreenName) followUser(client, userToFollow)
screenName = userToFollow
} }
} }
@@ -50,7 +64,7 @@ func optionFollowRandom(client *twitter.Client) {
firstScreenName, _ := newcommand.ReadString('\n') firstScreenName, _ := newcommand.ReadString('\n')
firstScreenName = strings.TrimSpace(firstScreenName) firstScreenName = strings.TrimSpace(firstScreenName)
fmt.Print("first user to follow: @") fmt.Print("first user to follow: @")
c.Purple(answer) c.Purple(firstScreenName)
c.Red("Are you sure? [y/n]") c.Red("Are you sure? [y/n]")
newcommand = bufio.NewReader(os.Stdin) newcommand = bufio.NewReader(os.Stdin)

View File

@@ -16,12 +16,29 @@ func printUserFollowsData(user *twitter.User) {
fmt.Print("following: ") fmt.Print("following: ")
c.Cyan(strconv.Itoa(user.FriendsCount)) c.Cyan(strconv.Itoa(user.FriendsCount))
} }
func unfollowFollowingUsers(client *twitter.Client, user *twitter.User) { func unfollowUser(client *twitter.Client, screenName string) {
following, _, _ := client.Friends.List(&twitter.FriendListParams{ _, httpResp, _ := client.Friendships.Destroy(&twitter.FriendshipDestroyParams{
ScreenName: screenName,
})
if httpResp.Status != "200 OK" {
c.Red(httpResp.Status)
}
}
func getFollowingUsers(client *twitter.Client, user *twitter.User) {
following, httpResp, err := client.Friends.List(&twitter.FriendListParams{
ScreenName: user.ScreenName, ScreenName: user.ScreenName,
Count: 200, Count: 200,
}) })
if err != nil {
fmt.Println(err)
}
if httpResp.Status != "200 OK" {
c.Red(httpResp.Status)
}
fmt.Println(following) fmt.Println(following)
for _, k := range following.Users {
unfollowUser(client, k.ScreenName)
}
} }
func optionUnfollowAll(client *twitter.Client) { func optionUnfollowAll(client *twitter.Client) {
fmt.Println("Getting user data...") fmt.Println("Getting user data...")
@@ -35,7 +52,7 @@ func optionUnfollowAll(client *twitter.Client) {
switch answer { switch answer {
case "y": case "y":
fmt.Println("ok, you are sure") fmt.Println("ok, you are sure")
unfollowFollowingUsers(client, user) getFollowingUsers(client, user)
break break
default: default:
fmt.Println("Operation cancelled") fmt.Println("Operation cancelled")