Skip to content

Commit

Permalink
[Add Example] See who doesn't follow back
Browse files Browse the repository at this point in the history
  • Loading branch information
nsa authored and dgrr committed Sep 16, 2018
1 parent 6e9b223 commit 9c8e3e6
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions examples/user/seeunfollowers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// +build ignore

package main

import (
"fmt"
"os"
"strings"

e "github.com/ahmdrz/goinsta/examples"
)

func main() {
var followers []string
var followings []string
inst, err := e.InitGoinsta("<target user>")
e.CheckErr(err)

user, err := inst.Profiles.ByName(os.Args[0])
e.CheckErr(err)

users_following := user.Following()
e.CheckErr(err)

users_follower := user.Followers()
e.CheckErr(err)

// collect usernames from Instagram following section
following_counter := 1
for users_following.Next() {
for _, user := range users_following.Users {
following_counter++
followings = append(followings, user.Username)
}
}

// collect usernames from Instagram followers section
follower_counter := 1
for users_follower.Next() {
for _, user := range users_follower.Users {
follower_counter++
followers = append(followers, user.Username)
}
}

fmt.Println("\nTOTAL FOLLOWING:", following_counter)
fmt.Println("TOTAL FOLLOWER:", follower_counter)
fmt.Println("TOTAL DOESN'T FOLLOW YOU BACK:", len(differ(followings, followers)))
fmt.Println("WHO DOESN'T FOLLOW YOU BACK:\n", strings.Trim(fmt.Sprint(differ(followings, followers)), "[]"))

if !e.UsingSession {
err = inst.Logout()
e.CheckErr(err)
}
}

func differ(a, b []string) (diff []string) {
m := make(map[string]bool)

for _, item := range b {
m[item] = true
}

for _, item := range a {
if _, ok := m[item]; !ok {
diff = append(diff, item)
}
}
return
}

0 comments on commit 9c8e3e6

Please sign in to comment.