Module: Modes
- Included in:
- ClassMethods
- Defined in:
- lib/botinsta/modes.rb
Overview
Contains bot modes. The bot has only one mode for now, which is tag based mode. In this mode bot works on a tag basis. Gets medias from specified tags,
likes them and follows the owner of the media until it fulfills
its like and follow limits for the day.
Instance Method Summary collapse
Instance Method Details
#tag_based_mode ⇒ Object
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 |
# File 'lib/botinsta/modes.rb', line 8 def tag_based_mode @tags.each do |tag| like_count = 0; follow_count = 0 is_first_page = true tag until like_count == @likes_per_tag && follow_count == @follows_per_tag if is_first_page set_query_id(tag) get_first_page_data(tag) is_first_page = false break if @page.medias_empty? elsif @page.next_page? get_next_page_data(tag) end @page.medias.each do |media| media.extend Hashie::Extensions::DeepFind @media = MediaData.new(media) next if @media.blacklisted_tag?(@tag_blacklist) # Here is the code for liking stuff. if like_count != @likes_per_tag if like_if_not_in_db(@media) like_count += 1 else (action: :like, data: @media.id) end end # Here is the code for following users. if follow_count != @follows_per_tag if get_user_page_data(@media.owner) && follow_if_not_in_db(@user) follow_count += 1 if follow_count == 1 else (action: :follow, data: @user.username) end end # Here is the code for unfollowing users if !@table_follows.empty? && unfollow_threshold_past?(@last_follow_time) && @total_unfollows != @unfollows_per_run if unfollow_user(@first_db_entry[:user_id]) @total_unfollows += 1 (action: :unfollow, number: @total_unfollows, data: @first_db_entry[:username]) delete_from_db(@first_db_entry[:user_id]) else false end end break if like_count == @likes_per_tag && follow_count == @follows_per_tag end end end rescue Interrupt logout exit end |