Last active
November 3, 2016 15:45
-
-
Save trmcnvn/fc1ec7aad37fb0a206a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Uses Steam Market backend URL to list cheapest knife available for CS:GO | |
# Checks if price is under the threshold and if so alert us | |
require 'httparty' | |
require 'nokogiri' | |
class Market | |
def initialize | |
# {"success":true,"start":0,"pagesize":100,"total_count":362,"results_html": ...} | |
@url = "http://steamcommunity.com/market/search/render/?query=appid%3A730%20Covert%20Knife&start=0&count=1&sort_dir=asc&sort_column=price" | |
@price_threshold = 10.00 | |
end | |
def find_knife | |
req = HTTParty.get(@url) | |
html = req["results_html"] | |
puts "Error: Unknown Response" unless html | |
doc = Nokogiri::HTML(html) | |
link = doc.css('a.market_listing_row_link')[0].attributes['href'].value | |
price = doc.css('span[style="color:white"]')[0].content | |
price = /(\d+.?\d+)/.match(price) | |
return if price[0].to_i > @price_threshold | |
puts "Knife Found! #{price} --- #{link}" | |
# Knife Found! 63.17 --- http://steamcommunity.com/market/listings/730/%E2%98%85%20Gut%20Knife%20%7C%20Safari%20Mesh%20%28Field-Tested%29?filter=Covert | |
end | |
end | |
# get them knives | |
market = Market.new | |
while true do | |
market.find_knife | |
sleep 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment