instabot 0.1.40 → 0.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,138 +1,82 @@
1
1
  module Grabber
2
-
3
- def get_user_informations(user_id)
4
- # puts "=".cyan*10
5
- # begin
6
- puts "[+] ".cyan + "Trying to get user (#{user_id}) informations"
7
- log("Trying to get user (#{user_id}) informations", "GRABBER")
8
- user_page = "https://www.instagram.com/web/friendships/#{user_id}/follow/"
9
- response = get_page(user_page)
10
- last_page = response.uri.to_s
11
- username = last_page.split('/')[3]
12
- pp username
13
- pp last_page
14
- response = @agent.get("https://instagram.com/#{username}/?__a=1")
15
- # rescue Exception => e
16
- # if response.code == "404"
17
- # puts "ERORR: [404] Notfound\t#{e.message}".red
18
- # exit!
19
- # elsif response.code == "403"
20
- # exit! if @error_403_times == 3
21
- # @error_403_times += 1
22
- # puts "ERROR: [403] (looks like you're banned from IG)".red
23
- # retry
24
- # end
25
- # end
26
- data = JSON.parse(response.body)
27
- data.extend Hashie::Extensions::DeepFind
28
-
29
- # File.open("body.json", "w+") {|file| file.puts data.extend Hashie::Extensions::DeepFind }
30
-
31
- @informations = {
32
- followers: data.deep_find("followed_by")["count"],
33
- following: data.deep_find("follows")["count"],
34
- is_private: data.deep_find("is_private"),
35
- is_verified: data.deep_find("is_verified"),
36
- username: data.deep_find("username"),
37
- full_name: data.deep_find("full_name"),
38
- id: data.deep_find("id")
39
- }
40
- # puts @informations
41
- end
42
-
43
- def get_media_informations(media_id)
44
- # puts "=".cyan*10
45
- puts "[+] ".cyan + "Trying to get media (#{media_id}) informations"
46
- log("Trying to get media (#{media_id}) informations","GRABBER")
47
- # begin
48
- response = @agent.get("https://www.instagram.com/p/#{media_id}/?__a=1")
49
- # rescue Exception => e
50
- # if response.code == "404"
51
- # puts "ERORR: [404] Notfound\t#{e.message}".red
52
- # exit!
53
- # elsif response.code == "403"
54
- # exit! if @error_403_times == 3
55
- # @error_403_times += 1
56
- # puts "ERROR: [403] (looks like you're banned from IG)".red
57
- # retry
58
- # end
59
- # end
60
- data = JSON.parse(response.body)
61
- data.extend Hashie::Extensions::DeepFind
62
- # pp data.extend Hashie::Extensions::DeepFind
63
-
64
- # puts data.deep_find('id')
65
- # puts data.deep_find('is_video')
66
- # puts data.deep_find('comments_disabled')
67
- # puts data.deep_find('viewer_has_liked')
68
- # puts data.deep_find('has_blocked_viewer')
69
- # puts data.deep_find('followed_by_viewer')
70
- # puts data.deep_find('full_name')
71
- # puts data.deep_find('is_private')
72
- # puts data.deep_find('is_verified')
73
- # puts data.deep_find('requested_by_viewer')
74
-
75
- @informations = {
76
- id: data.deep_find("id"),
77
- is_video: data.deep_find("is_video"),
78
- comments_disabled: data.deep_find("comments_disabled"),
79
- viewer_has_liked: data.deep_find("viewer_has_liked"),
80
- has_blocked_viewer: data.deep_find("has_blocked_viewer"),
81
- followed_by_viewer: data.deep_find("followed_by_viewer"),
82
- full_name: data.deep_find("full_name"),
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
@@ -1,58 +1,58 @@
1
1
  module Log
2
-
3
- def check_log_files
4
- puts "PROCESSING: ".cyan.bold + "checking log files"
5
- log("checking log files", "LOGGER")
6
- if !File.exists?(@logs_dir)
7
- Dir.mkdir(@logs_dir)
8
- end
9
-
10
- if options[:pre_load]
11
- if Dir.exists?('./logs')
12
- files = ["commented_medias", "followed_users", "liked_medias", "unfollowed_users"]
13
- files.each do |file|
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
-
23
- def write_file(filename, text="")
24
- File.open("#{@logs_dir}/#{filename}", "a+") {|file| file.print "#{text.chomp},"}
25
- end
26
-
27
- def log(text="",from="")
28
- time = Time.new.strftime("%H:%M:%S %y-%m-%d")
29
- if File.exists?(@logs_dir)
30
- File.open("#{@logs_dir}/logs-#{@global_time}.log","a+") do |log_file|
31
- log_file.puts "[#{@log_counter}] [#{time}] [#{from}] -- : #{text}"
32
- end
33
- else
34
- Dir.mkdir(@logs_dir)
35
- end
36
- @log_counter += 1
37
- end
38
-
39
- def save_action_data(id=0,type=:default)
40
- case type
41
- when :follow
42
- write_file("followed_users.txt",id)
43
- when :unfollow
44
- write_file("unfollowed_users.txt",id)
45
- when :like
46
- write_file("liked_medias.txt",id)
47
- when :comment
48
- write_file("commented_medias.txt",id)
49
- when :default
50
- puts "please choose a type"
51
- else
52
- puts "please choose a type"
53
- end
54
- end
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
@@ -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
- def login(username="", password="")
4
- if @login_mode == :manual
5
- username = username.to_s
6
- password = password.to_s
7
- else
8
- username = options[:username]
9
- password = options[:password]
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
- def logout
48
- log("trying to logout", "LOGIN")
49
- puts "[+] ".cyan + "Trying to logging out"
50
- set_mechanic_data
51
- logout_page = @agent.get("https://www.instagram.com/accounts/logout/")
52
- @logout_status = true
53
- log("successfully logged out", "LOGIN")
54
- puts "[+] ".cyan + "Successfully logged out"
55
- end
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
- def check_login_status(mode=:default)
58
- puts "[+] ".cyan + "Checking login status" if @login_mode != :manual
59
- log("checking loging status", "LOGIN")
60
- if @login_status
61
- return true
62
- else
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
- # return false
75
- # end
76
- end
77
- end
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
- end
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