botinsta 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c12d05858b8f49816a4619aaf56654763dc15168a72ec7c90e9abfe8c1b1a78
4
- data.tar.gz: 99af2f029b4fc83d1a8333172d42d4976e879db72aae4f67cf985296ff92dd11
3
+ metadata.gz: 35dc6b56dac3eb29498b327a357a0de793869e6b292a21f246ee7124be359826
4
+ data.tar.gz: 8ae761a8f914882f7dbceaeba56133f1e9f3896f0e72d0a4163cd7d23f4e9f77
5
5
  SHA512:
6
- metadata.gz: cc30b084e633a2be656fa32d37dacc8759ab7901d6369191349e8658ef036f798ed578b95993c55e6b916c4a0e042c9c0a292fa2387c7254d0d85b4e88b8516d
7
- data.tar.gz: b2d53a7a4d6a7481d47596bba8a7d78b901c43dd730e8868175fa868d577e7be282fa9e3cf19e5c3909f7d4898ff68833541416526c06fb317e65cfd4f5d1676
6
+ metadata.gz: cb3716427be71e812ad14c3a4eaec24eabe2066f210aeff92a043e14577ed9279ed8ec223a1bdf454a23769f3ed98a88cf8572cb4d88bf4525a34824b98c91b5
7
+ data.tar.gz: cb5d9e1c63d95e601ef50e9cae053180e0c7a8f8f47a198c206ed07b44d41c45165e16e963e43ec722db2a8ba3210b673d563c6232cf7fd13df76d2e54e4345a
@@ -3,10 +3,15 @@ require 'botinsta'
3
3
  bot = Botinsta.new ({ username: 'YOUR_USERNAME',
4
4
  password: 'YOUR_PASSWORD',
5
5
  tags: ['photography','vsco','b&w'],
6
- likes_per_tag: 60,
7
6
  tag_blacklist: ['nsfw','sexy','hot'],
7
+ likes_per_tag: 60,
8
8
  unfollows_per_run: 200,
9
- follows_per_tag: 10
9
+ follows_per_tag: 10,
10
+ unfollow_threshold: { seconds: 0,
11
+ minutes: 0,
12
+ hours: 1,
13
+ days: 0
14
+ }
10
15
  })
11
16
 
12
17
  bot.start
@@ -5,6 +5,8 @@ require 'mechanize'
5
5
  require 'sequel'
6
6
  require 'sqlite3'
7
7
  require 'nokogiri'
8
+ require 'rb-readline'
9
+ require 'pry'
8
10
 
9
11
  require_relative 'botinsta/class_methods'
10
12
 
@@ -14,26 +16,32 @@ class Botinsta
14
16
 
15
17
  include ClassMethods
16
18
 
17
- DEFAULT_PARAMETERS = { tags: %w[photography fotografia vsco],
18
- tag_blacklist: %w[nsfw hot sexy],
19
- user_blacklist: [],
20
- likes_per_tag: 10,
21
- unfollows_per_run: 200,
22
- follows_per_tag: 50
19
+ DEFAULT_PARAMETERS = { tags: %w[photography fotografia vsco],
20
+ tag_blacklist: %w[nsfw hot sexy],
21
+ user_blacklist: [],
22
+ likes_per_tag: 10,
23
+ follows_per_tag: 50,
24
+ unfollows_per_run: 200,
25
+ unfollow_threshold: { seconds: 0,
26
+ minutes: 0,
27
+ hours: 1,
28
+ days: 0
29
+ }
23
30
  }.freeze
24
31
 
25
32
  def initialize(**params)
26
33
 
27
34
  params = DEFAULT_PARAMETERS.merge(params)
28
35
 
29
- @username = params[:username]
30
- @password = params[:password]
31
- @tags = params[:tags]
32
- @tag_blacklist = params[:tag_blacklist]
33
- @user_blacklist = params[:user_blacklist]
34
- @likes_per_tag = params[:likes_per_tag]
35
- @follows_per_tag = params[:follows_per_tag]
36
- @unfollows_per_run = params[:unfollows_per_run]
36
+ @username = params[:username]
37
+ @password = params[:password]
38
+ @tags = params[:tags]
39
+ @tag_blacklist = params[:tag_blacklist]
40
+ @user_blacklist = params[:user_blacklist]
41
+ @likes_per_tag = params[:likes_per_tag]
42
+ @follows_per_tag = params[:follows_per_tag]
43
+ @unfollows_per_run = params[:unfollows_per_run]
44
+ @unfollow_threshold = params[:unfollow_threshold]
37
45
 
38
46
  @total_likes = 0
39
47
  @total_follows = 0
@@ -8,7 +8,8 @@ require_relative 'modes'
8
8
  require_relative 'pages'
9
9
  require_relative 'requests'
10
10
 
11
-
11
+ # This is just a wrap up module
12
+ # for other modules and classes. To include them all at once!
12
13
  module ClassMethods
13
14
 
14
15
  include Actions
@@ -11,7 +11,7 @@ class MediaData
11
11
  @is_video = data.deep_find('is_video')
12
12
  @comments_disabled = data.deep_find('comments_disabled')
13
13
  @text = data.deep_find('text')
14
- @tags = @text.scan(/#[a-zA-Z0-9]+/)
14
+ @tags = @text.nil? ? [] : @text.scan(/#[a-zA-Z0-9]+/)
15
15
  @shortcode = data.deep_find('shortcode')
16
16
 
17
17
  end
@@ -145,12 +145,19 @@ module Helpers
145
145
  @table_follows.where(user_id: user_id).delete
146
146
  end
147
147
 
148
- # Calculates if a day is past since the first follow entry in the database.
148
+ # Calculates whether the given threshold is past or not to
149
+ # start unfollowing users from the database.
149
150
  #
150
151
  # @param last_time [Time] a Time instance, used with @last_follow_time.
151
152
  # @return [Boolean] true if a day is past since
152
153
  # the first follow entry in the database, false otherwise.
153
- def one_day_past?(last_time)
154
- ((Time.now - last_time) / 86_400) >= 1
154
+ def unfollow_threshold_past?(last_time)
155
+ days = @unfollow_threshold[:days] ||= 0
156
+ hours = @unfollow_threshold[:hours] ||= 0
157
+ minutes = @unfollow_threshold[:minutes] ||= 0
158
+ seconds = @unfollow_threshold[:seconds] ||= 0
159
+
160
+ total_in_seconds = days * 86_400 + hours * 3600 + minutes * 60 + seconds
161
+ ((Time.now - last_time) / total_in_seconds) >= 1
155
162
  end
156
163
  end
@@ -17,7 +17,7 @@ module Modes
17
17
  get_first_page_data(tag)
18
18
  is_first_page = false
19
19
  break if @page.medias_empty?
20
- elsif like_count == @page.media_count && @page.has_next_page?
20
+ elsif @page.next_page?
21
21
  get_next_page_data(tag)
22
22
  end
23
23
  @page.medias.each do |media|
@@ -45,7 +45,7 @@ module Modes
45
45
  end
46
46
 
47
47
  # Here is the code for unfollowing users
48
- if !@table_follows.empty? && one_day_past?(@last_follow_time) && @total_unfollows != @unfollows_per_run
48
+ if !@table_follows.empty? && unfollow_threshold_past?(@last_follow_time) && @total_unfollows != @unfollows_per_run
49
49
  if unfollow_user(@first_db_entry[:user_id])
50
50
  @total_unfollows += 1
51
51
  print_success_message(action: :unfollow, number: @total_unfollows,
@@ -50,7 +50,7 @@ module Pages
50
50
  # @param (see #set_query_id)
51
51
  def get_next_page_data(tag)
52
52
  print_time_stamp
53
- puts 'Getting the next page for the tag '.colorize(:red) + "#{tag}"
53
+ puts 'Getting the next page for the tag '.colorize(:blue) + "#{tag}"
54
54
  next_page_link = "https://www.instagram.com/graphql/query/?query_hash=#{@query_id}&"\
55
55
  "variables={\"tag_name\":\"#{tag}\"," \
56
56
  "\"first\":10,\"after\":\"#{@page.end_cursor}\"}"
@@ -1,3 +1,3 @@
1
1
  class Botinsta
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botinsta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - andreyuhai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-19 00:00:00.000000000 Z
11
+ date: 2018-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize