/
main.go
154 lines (146 loc) · 3.52 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"bufio"
"container/ring"
"fmt"
"github.com/buger/jsonparser"
"github.com/spf13/viper"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"os/exec"
"time"
)
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}
func AppendStringToFile(path, text string) error {
f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(text+"\n")
if err != nil {
return err
}
return nil
}
func main() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config.json file: %s \n", err))
}
file, err := os.Open(viper.GetString("list"))
if err != nil {
log.Fatal(err)
}
defer file.Close()
usernamechannel := make(chan string)
proxychannel := make(chan string)
removechannel := make(chan string)
go func() {
for{
removethis := <- removechannel
userlist := viper.GetString("list")
out , err := exec.Command("sed","-i'.bak'","-e","s/"+ removethis + "//g",userlist).CombinedOutput()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + string(out))
} else{
output := string(out[:])
fmt.Println(output)
}
}
}()
for i := 0; i <= viper.GetInt("threads") ; i++ {
go func(){
for {
usernameprovided := <-usernamechannel
urlStr := "https://www.instagram.com/web/search/topsearch/?query=" + usernameprovided
url, err := url.Parse(urlStr)
if err != nil {
log.Println(err)
}
proxyStr := "http://" + <-proxychannel
proxyURL, err := url.Parse(proxyStr)
if err != nil {
log.Println(err)
}
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
client := &http.Client{
Transport: transport,
}
request, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
log.Println(err)
}
response, err := client.Do(request)
if err != nil {
log.Println(err)
} else{
data, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Println(err)
}
bytedata := []byte(data)
username,_ := jsonparser.GetString(bytedata, "users", "[0]", "user", "username")
if usernameprovided == username{
fmt.Print(username + " - ")
followers , _ := jsonparser.GetInt(bytedata, "users", "[0]", "user", "follower_count")
if err != nil{
log.Println(err)
}
fmt.Println(followers)
if followers > 0{
removechannel <- username
}
if followers >= 1000{
AppendStringToFile(viper.GetString("over10kfile"), username)
}else{
AppendStringToFile(viper.GetString("under10kfile"), username)
}
}
defer response.Body.Close()
}
}
}()
}
proxies, err := readLines(viper.GetString("proxyfile"))
if err != nil {
log.Fatalf("readLines: %s", err)
}
proxyring := ring.New(len(proxies))
for i := 0; i < proxyring.Len(); i++ {
proxyring.Value = proxies[i]
proxyring = proxyring.Next()
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if scanner.Text() != "" {
usernamechannel <- scanner.Text()
proxychannel <- proxyring.Value.(string)
delay := viper.GetInt("delay")
time.Sleep(time.Duration(delay) * time.Second)
proxyring = proxyring.Next()
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}