-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow.go
76 lines (62 loc) · 1.57 KB
/
follow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cmd
import (
"context"
"fmt"
"log"
firebase "firebase.google.com/go"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/api/option"
"github.com/pinheirolucas/insta_cleaner/helper"
"github.com/pinheirolucas/insta_cleaner/whitelist"
)
// followCmd represents the follow command
var followCmd = &cobra.Command{
Use: "follow",
Short: "Follow a list of users by name",
Run: runFollow,
}
func init() {
userCmd.AddCommand(followCmd)
}
func runFollow(cmd *cobra.Command, usernames []string) {
if len(usernames) == 0 {
createError("no usernames provided")
}
c, err := loadConfig()
if err != nil {
handleError(err)
}
insta, err := helper.InitLocalGoinsta(c.username, c.password, c.session)
if err != nil {
log.Fatalf("helper.InitLocalGoinsta: %v \n", err)
}
app, err := firebase.NewApp(
context.Background(),
&firebase.Config{
DatabaseURL: c.databaseURL,
},
option.WithCredentialsFile(c.credentials),
)
if err != nil {
log.Fatalf("firebase.NewApp: %v \n", err)
}
whitelistService, err := whitelist.NewService(context.Background(), viper.GetString("whitelist_service_type"), app)
if err != nil {
log.Fatalf("whitelist.NewService: %v \n", err)
}
for _, uname := range usernames {
log.Printf("following %s \n", uname)
user, err := insta.Profiles.ByName(uname)
if err != nil {
fmt.Printf("not able to follow %s ignoring", uname)
continue
}
if err = user.Follow(); err != nil {
handleError(err)
}
if err := whitelistService.CreateIfNotExists(user.ID, user.Username); err != nil {
handleError(err)
}
}
}