-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.go
71 lines (57 loc) · 1.65 KB
/
clean.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
package cmd
import (
"context"
"log"
firebase "firebase.google.com/go"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/api/option"
"github.com/pinheirolucas/insta_cleaner/cleaner"
"github.com/pinheirolucas/insta_cleaner/helper"
"github.com/pinheirolucas/insta_cleaner/logger"
"github.com/pinheirolucas/insta_cleaner/whitelist"
)
var limit uint32
// cleanCmd represents the clean command
var cleanCmd = &cobra.Command{
Use: "clean",
Short: "Starts the instagram clean job",
Run: runClean,
}
func init() {
rootCmd.AddCommand(cleanCmd)
cleanCmd.Flags().Uint32VarP(&limit, "limit", "l", 10, "limit of unfollows")
}
func runClean(cmd *cobra.Command, args []string) {
if limit < 0 {
createError("limit must bem greater than 0")
}
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)
}
instagramService := cleaner.NewGoinstaInstagramService(insta)
l := logger.NewDefault()
service := cleaner.NewService(instagramService, whitelistService, l, cleaner.WithMaxUnfollows(limit))
if err := service.Clean(); err != nil {
log.Fatalf("(*cleaner.Service).Clean: %v \n", err)
}
}