Skip to content

Instantly share code, notes, and snippets.

@b1nary
Last active February 11, 2016 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b1nary/69f7a6ec32967e363c9b to your computer and use it in GitHub Desktop.
Save b1nary/69f7a6ec32967e363c9b to your computer and use it in GitHub Desktop.
Flippa Ending Soon Robot for Slack

FlippSlacka

Installation:

I assume you run Linux and have ruby installed.

  • wget https://gist.githubusercontent.com/b1nary/69f7a6ec32967e363c9b/raw/flippslacka.rb
  • chmod +x flippslacka.rb
  • crontab -e
  • Add: 30 9 * * * ruby /path/to/flippslacka.rb

This runs once a day on 9:30.

Screenshot

require 'open-uri'
require 'slack-notifier'
class FlippSlacka
# Slack Webhook
SLACK_WEBHOOK = "https://hooks.slack.com/services/XXXX/XXXX/XXXXXXXX"
SLACK_CHANNEL = "#flippa"
SLACK_USERNAME = "Flippa Robot"
SLACK_AVATAR = "http://www.techlivewire.com/wp-content/uploads/2014/09/Flippa-logo1.png"
# Flippa Config
DOMAIN = "https://flippa.com/"
DEFAULT_PATH = "domains/ending-soon"
# May be "nil" aswell to ignore filter
MINIMAL_CHAR_COUNT = 1
MAXIMAL_CHAR_COUNT = 6
MINIMAL_PRICE = 0
MAXIMAL_PRICE = 100
def scan
slack.ping "Todays Flippa offers! Yay :heart:", attachments: (parse_page.map do |domain|
_end = Time.parse(domain['ends_at']).to_i.duration
next if domain['property_name'].strip.include? ' ' || _end.nil?
{
fallback: domain['property_name'],
text: "<#{domain['html_url']}|#{domain['property_name']}> *$ #{domain['current_price']}* _(#{domain['bid_count']})_ `#{_end} left`",
color: domain['bid_count'].to_i > 0 ? "warning" : "good",
mrkdwn_in: ["text"]
}
end.compact)
end
def parse_page
JSON.parse(
open(DOMAIN+DEFAULT_PATH+domain_append).read
.split('"searchResults":').last
.split(',"altResults":').first
).first.last['data']
end
def domain_append
append = ""
append += "?"
append += "&domain_characters_count_min=#{MINIMAL_CHAR_COUNT}" if MINIMAL_CHAR_COUNT > 1
append += "&domain_characters_count_max=#{MAXIMAL_CHAR_COUNT}" if MAXIMAL_CHAR_COUNT
append += "&price_min=#{MINIMAL_PRICE}" if MINIMAL_PRICE
append += "&price_max=#{MAXIMAL_PRICE}" if MAXIMAL_PRICE
append += "&sort_alias=ending_soon"
append.gsub('?&','?')
end
def slack
@slack ||= Slack::Notifier.new SLACK_WEBHOOK,
channel: SLACK_CHANNEL,
username: SLACK_USERNAME,
icon_url: SLACK_AVATAR
end
end
class Numeric
def duration
secs = (Time.now.to_i - self.to_int)*-1
mins = secs / 60
hours = mins / 60
days = hours / 24
if days > 0
"#{days} days and #{hours % 24} hours"
elsif hours > 0
"#{hours} hours and #{mins % 60} minutes"
elsif mins > 0
"#{mins} minutes and #{secs % 60} seconds"
elsif secs >= 0
"#{secs} seconds"
end
end
end
FlippSlacka.new.scan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment