instabot 0.1.40 → 0.1.52
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/instabot.rb +10 -10
- data/lib/instabot/actions.rb +50 -45
- data/lib/instabot/banner.rb +10 -12
- data/lib/instabot/config.rb +29 -28
- data/lib/instabot/core.rb +66 -116
- data/lib/instabot/create_protocol.rb +39 -47
- data/lib/instabot/grabber.rb +81 -137
- data/lib/instabot/logger.rb +57 -57
- data/lib/instabot/login.rb +56 -73
- data/lib/instabot/modes.rb +208 -252
- data/lib/instabot/version.rb +5 -5
- metadata +31 -17
data/lib/instabot/grabber.rb
CHANGED
@@ -1,138 +1,82 @@
|
|
1
1
|
module Grabber
|
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
|
-
is_private: data.deep_find("is_private"),
|
84
|
-
is_verified: data.deep_find("is_verified"),
|
85
|
-
requested_by_viewer: data.deep_find("requested_by_viewer"),
|
86
|
-
text: data.deep_find("text")
|
87
|
-
}
|
88
|
-
unless @infinite_tags == true
|
89
|
-
# puts "in infinity".upcase.cyan.bold
|
90
|
-
tags = @informations[:text].encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'}).split(/\W+/)
|
91
|
-
id = 0
|
92
|
-
tags.each do |tag|
|
93
|
-
if tag == "_" || tag == "" || tag.nil?
|
94
|
-
tags.delete(tag)
|
95
|
-
else
|
96
|
-
id += 1
|
97
|
-
Config.options.tags << tag
|
98
|
-
end
|
99
|
-
end
|
100
|
-
puts "[+] ".cyan + "[" + "#{id}".yellow + "] New tags added"
|
101
|
-
# pp Config.options.tags
|
102
|
-
end
|
103
|
-
# puts @informations
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
def search(tags=[])
|
110
|
-
tags.each do |tag|
|
111
|
-
url = "https://www.instagram.com/explore/tags/#{tag}/?__a=1"
|
112
|
-
puts "[+] ".cyan + "Searching in hashtags [##{tag}]"
|
113
|
-
log("Searching in hashtags [##{tag}]", "GRABBER")
|
114
|
-
response = @agent.get(url)
|
115
|
-
# puts response.body.to_s.cyan[0..50]
|
116
|
-
data = JSON.parse(response.body)
|
117
|
-
data.extend Hashie::Extensions::DeepFind
|
118
|
-
owners = data.deep_find_all("owner")
|
119
|
-
media_codes = data.deep_find_all("code")
|
120
|
-
owners.map { |id| users << id['id']}
|
121
|
-
media_codes.map {|code| medias << code}
|
122
|
-
Config.options.tags.delete(tag)
|
123
|
-
end
|
124
|
-
puts "[+] ".cyan + "Total grabbed users [" + "#{users.size}".yellow + "]"
|
125
|
-
puts "[+] ".cyan + "Total grabbed medias [" + "#{medias.size}".yellow + "]"
|
126
|
-
log("Total grabbed users(#{users.size}) & Total grabbed medias(#{medias.size})", "GRABBER")
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
2
|
+
def get_user_informations(user_id)
|
3
|
+
puts '[+] '.cyan + "Trying to get user (#{user_id}) informations"
|
4
|
+
log("Trying to get user (#{user_id}) informations", 'GRABBER')
|
5
|
+
user_page = "https://www.instagram.com/web/friendships/#{user_id}/follow/"
|
6
|
+
response = get_page(user_page)
|
7
|
+
last_page = response.uri.to_s
|
8
|
+
username = last_page.split('/')[3]
|
9
|
+
response = @agent.get("https://instagram.com/#{username}/?__a=1")
|
10
|
+
data = parse_response(response.body)
|
11
|
+
|
12
|
+
@informations = {
|
13
|
+
followers: data.deep_find('followed_by')['count'],
|
14
|
+
following: data.deep_find('follows')['count'],
|
15
|
+
is_private: data.deep_find('is_private'),
|
16
|
+
is_verified: data.deep_find('is_verified'),
|
17
|
+
username: data.deep_find('username'),
|
18
|
+
full_name: data.deep_find('full_name'),
|
19
|
+
id: data.deep_find('id')
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_media_informations(media_id)
|
24
|
+
puts '[+] '.cyan + "Trying to get media (#{media_id}) informations"
|
25
|
+
log("Trying to get media (#{media_id}) informations", 'GRABBER')
|
26
|
+
response = @agent.get("https://www.instagram.com/p/#{media_id}/?__a=1")
|
27
|
+
data = parse_response(response.body)
|
28
|
+
|
29
|
+
@informations = {
|
30
|
+
id: data.deep_find('id'),
|
31
|
+
is_video: data.deep_find('is_video'),
|
32
|
+
comments_disabled: data.deep_find('comments_disabled'),
|
33
|
+
viewer_has_liked: data.deep_find('viewer_has_liked'),
|
34
|
+
has_blocked_viewer: data.deep_find('has_blocked_viewer'),
|
35
|
+
followed_by_viewer: data.deep_find('followed_by_viewer'),
|
36
|
+
full_name: data.deep_find('full_name'),
|
37
|
+
is_private: data.deep_find('is_private'),
|
38
|
+
is_verified: data.deep_find('is_verified'),
|
39
|
+
requested_by_viewer: data.deep_find('requested_by_viewer'),
|
40
|
+
text: data.deep_find('text')
|
41
|
+
}
|
42
|
+
unless @infinite_tags == true
|
43
|
+
tags = @informations[:text].encode('UTF-8', invalid: :replace, undef: :replace, replace: '?').split(/\W+/)
|
44
|
+
id = 0
|
45
|
+
tags.each do |tag|
|
46
|
+
if tag == '_' || tag == '' || tag.nil?
|
47
|
+
tags.delete(tag)
|
48
|
+
else
|
49
|
+
id += 1
|
50
|
+
Config.options.tags << tag
|
51
|
+
end
|
52
|
+
end
|
53
|
+
puts '[+] '.cyan + '[' + id.to_s.yellow + '] New tags added'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def search(tags = [])
|
58
|
+
tags.each do |tag|
|
59
|
+
puts '[+] '.cyan + "Searching in hashtag [##{tag}]"
|
60
|
+
log("Searching in hashtags [##{tag}]", 'GRABBER')
|
61
|
+
url = "https://www.instagram.com/explore/tags/#{tag}/?__a=1"
|
62
|
+
response = @agent.get(url)
|
63
|
+
data = parse_response(response.body)
|
64
|
+
owners = data.deep_find_all('owner')
|
65
|
+
media_codes = data.deep_find_all('code')
|
66
|
+
owners.map { |id| users << id['id'] }
|
67
|
+
media_codes.map { |code| medias << code }
|
68
|
+
Config.options.tags.delete(tag)
|
69
|
+
end
|
70
|
+
puts '[+] '.cyan + 'Total grabbed users [' + users.size.to_s.yellow + ']'
|
71
|
+
puts '[+] '.cyan + 'Total grabbed medias [' + medias.size.to_s.yellow + ']'
|
72
|
+
log("Total grabbed users(#{users.size}) & Total grabbed medias(#{medias.size})", 'GRABBER')
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def parse_response(body)
|
78
|
+
data = JSON.parse(body)
|
79
|
+
data.extend Hashie::Extensions::DeepFind
|
80
|
+
data
|
81
|
+
end
|
82
|
+
end
|
data/lib/instabot/logger.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
1
|
module Log
|
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
|
-
end
|
57
|
-
|
58
|
-
|
2
|
+
def check_log_files
|
3
|
+
puts 'PROCESSING: '.cyan.bold + 'checking log files'
|
4
|
+
log('checking log files', 'LOGGER')
|
5
|
+
unless File.exists?(@logs_dir)
|
6
|
+
Dir.mkdir(@logs_dir)
|
7
|
+
end
|
8
|
+
|
9
|
+
if options[:pre_load]
|
10
|
+
if Dir.exists?('./logs')
|
11
|
+
files = %w[commented_medias followed_users liked_medias unliked_medias unfollowed_users]
|
12
|
+
files.each do |file|
|
13
|
+
if File.exists?("./logs/#{file}.txt")
|
14
|
+
File.open("./logs/#{file}.txt", 'r+') do |buffer|
|
15
|
+
data = buffer.read.split(',')
|
16
|
+
@local_stroage[file.to_sym] = data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_file(filename, text = '')
|
25
|
+
File.open("#{@logs_dir}/#{filename}", 'a+') { |f| f.print "#{text.chomp}," }
|
26
|
+
end
|
27
|
+
|
28
|
+
def log(text = '', from = '')
|
29
|
+
time = Time.new.strftime('%H:%M:%S %y-%m-%d')
|
30
|
+
if File.exists?(@logs_dir)
|
31
|
+
File.open("#{@logs_dir}/logs-#{@global_time}.log", 'a+') do |log_file|
|
32
|
+
log_file.puts "[#{@log_counter}] [#{time}] [#{from}] -- : #{text}"
|
33
|
+
end
|
34
|
+
else
|
35
|
+
Dir.mkdir(@logs_dir)
|
36
|
+
end
|
37
|
+
@log_counter += 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def save_action_data(id = 0, type = :default)
|
41
|
+
case type
|
42
|
+
when :follow
|
43
|
+
write_file('followed_users.txt', id)
|
44
|
+
when :unfollow
|
45
|
+
write_file('unfollowed_users.txt', id)
|
46
|
+
when :like
|
47
|
+
write_file('liked_medias.txt', id)
|
48
|
+
when :unlike
|
49
|
+
write_file('unliked_medias.txt', id)
|
50
|
+
when :comment
|
51
|
+
write_file('commented_medias.txt', id)
|
52
|
+
when :default
|
53
|
+
puts 'please choose a type'
|
54
|
+
else
|
55
|
+
puts 'please choose a type'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/instabot/login.rb
CHANGED
@@ -1,79 +1,62 @@
|
|
1
1
|
module Login
|
2
|
+
def login(username = '', password = '')
|
3
|
+
if @login_mode == :manual
|
4
|
+
username = username.to_s
|
5
|
+
password = password.to_s
|
6
|
+
else
|
7
|
+
username = options[:username]
|
8
|
+
password = options[:password]
|
9
|
+
end
|
2
10
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
log("Trying to login into [#{username}] account", "LOGIN")
|
12
|
-
puts "[+] ".cyan + "Trying to login into [#{username}] account"
|
13
|
-
login_page = @agent.get("https://www.instagram.com/accounts/login/?force_classic_login")
|
14
|
-
page_form = login_page.forms.last
|
15
|
-
page_form.username = username
|
16
|
-
page_form.password = password
|
17
|
-
page = page_form.submit
|
18
|
-
# pp page
|
19
|
-
# puts "=".cyan*100
|
20
|
-
# pp page.body
|
21
|
-
# puts "=".cyan*100
|
22
|
-
# pp page.code
|
23
|
-
# puts "=".cyan*100
|
24
|
-
|
25
|
-
# puts "=".cyan*100
|
26
|
-
# pp @agent.history.last.uri
|
27
|
-
if page.code == "200" && page.uri.to_s != "https://www.instagram.com/accounts/login/?force_classic_login" && !"#{page.uri.to_s}".include?("challenge")
|
28
|
-
@login_status = true
|
29
|
-
log("successfully logged in","LOGIN")
|
30
|
-
puts "[+] ".cyan + "Successfully logged in".green.bold
|
31
|
-
else
|
32
|
-
@login_status = false
|
33
|
-
if "#{page.uri.to_s}".include?("challenge")
|
34
|
-
puts "[-] ".cyan + "Your account needs veryfication or it has banned from instagram".red.bold
|
35
|
-
else
|
36
|
-
puts "[-] ".cyan + "Invalid username or password".red.bold
|
37
|
-
end
|
38
|
-
check_login_status()
|
39
|
-
end
|
40
|
-
rescue Exception => e
|
41
|
-
log("an error detected: #{e.class} #{e} #{e.backtrace}","LOGIN")
|
42
|
-
@login_status = false
|
43
|
-
puts "[-] ".cyan + "#{e.class} #{e.message}".red
|
44
|
-
exit
|
45
|
-
end
|
11
|
+
log('trying to login', 'LOGIN')
|
12
|
+
puts '[+] '.cyan + "Trying to login into [#{username}] account"
|
13
|
+
login_page = @agent.get('https://www.instagram.com/accounts/login/?force_classic_login')
|
14
|
+
page_form = login_page.forms.last
|
15
|
+
page_form.username = username
|
16
|
+
page_form.password = password
|
17
|
+
page = page_form.submit
|
46
18
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
19
|
+
if page.code == '200' && page.uri.to_s != 'https://www.instagram.com/accounts/login/?force_classic_login' && !page.uri.to_s.include?('challenge')
|
20
|
+
@login_status = true
|
21
|
+
log('successfully logged in', 'LOGIN')
|
22
|
+
puts '[+] '.cyan + 'Successfully logged in'.green.bold
|
23
|
+
else
|
24
|
+
@login_status = false
|
25
|
+
if page.uri.to_s.include?('challenge')
|
26
|
+
puts '[-] '.cyan + 'Your account needs veryfication or it has been banned from instagram'.red.bold
|
27
|
+
else
|
28
|
+
puts '[-] '.cyan + 'Invalid username or password'.red.bold
|
29
|
+
end
|
30
|
+
check_login_status
|
31
|
+
end
|
56
32
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
puts "[-] [##{@login_counter}] ".cyan + "You're not logged in (or it is an error with the request)\t[TRYING AGAIN]".red.bold
|
64
|
-
# if @login_mode != :manual
|
65
|
-
# if mode == :auto_retry
|
66
|
-
exit! if @login_counter == 3
|
67
|
-
@login_counter += 1
|
68
|
-
login
|
69
|
-
# else
|
70
|
-
# exit!
|
71
|
-
# end
|
72
|
-
# else
|
33
|
+
rescue Exception => e
|
34
|
+
log("an error detected: #{e.class} #{e} #{e.backtrace}", 'LOGIN')
|
35
|
+
@login_status = false
|
36
|
+
puts '[-] '.cyan + "#{e.class} #{e.message}\n check out the log file for full trace ".red
|
37
|
+
exit
|
38
|
+
end
|
73
39
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
40
|
+
def logout
|
41
|
+
log('trying to logout', 'LOGIN')
|
42
|
+
puts '[+] '.cyan + 'Trying to logging out'
|
43
|
+
set_mechanic_data
|
44
|
+
@agent.get('https://www.instagram.com/accounts/logout/')
|
45
|
+
@logout_status = true
|
46
|
+
log('successfully logged out', 'LOGIN')
|
47
|
+
puts '[+] '.cyan + 'Successfully logged out'
|
48
|
+
end
|
78
49
|
|
79
|
-
|
50
|
+
def check_login_status(_mode = :default)
|
51
|
+
puts '[+] '.cyan + 'Checking login status' if @login_mode != :manual
|
52
|
+
log('checking loging status', 'LOGIN')
|
53
|
+
if @login_status
|
54
|
+
return true
|
55
|
+
else
|
56
|
+
puts "[-] [##{@login_counter}] ".cyan + "You're not logged in (or it is an error with the request)\t[TRYING AGAIN]".red.bold
|
57
|
+
exit! if @login_counter == 3
|
58
|
+
@login_counter += 1
|
59
|
+
login
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|