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) {
tweets := getTweets(client, user.ScreenName, iterationsCount)
count := 0
fmt.Println(tweets)
//fmt.Println(tweets)
for _, v := range tweets {
c.Red("deleting: [id: " + v.IDStr + "] " + v.Text)
deleted, _, _ := client.Statuses.Destroy(v.ID, nil)

View File

@@ -14,21 +14,35 @@ import (
}*/
func getUserFollower(client *twitter.Client) string {
ScreenName := "username"
return ScreenName
func getUserToFollowFromUser(client *twitter.Client, fromUser string) string {
friends, httpResp, err := client.Friends.List(&twitter.FriendListParams{
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")
//screenName := firstScreenName
for i := 0; i < nFollow; i++ {
ScreenName = getUserFollower(client)
followUser(client, ScreenName)
userToFollow := getUserToFollowFromUser(client, screenName)
followUser(client, userToFollow)
screenName = userToFollow
}
}
@@ -50,7 +64,7 @@ func optionFollowRandom(client *twitter.Client) {
firstScreenName, _ := newcommand.ReadString('\n')
firstScreenName = strings.TrimSpace(firstScreenName)
fmt.Print("first user to follow: @")
c.Purple(answer)
c.Purple(firstScreenName)
c.Red("Are you sure? [y/n]")
newcommand = bufio.NewReader(os.Stdin)

View File

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