-
-
Save hiroto-takatoshi/555d531a23749a48535acc3ba578caa2 to your computer and use it in GitHub Desktop.
Get stocks for the GTA V BAWSAQ
This file contains hidden or 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
require 'net/http' | |
require 'json' | |
def request | |
Net::HTTP.get(URI('http://socialclub.rockstargames.com/games/gtav/ps4/bawsaq')) | |
uri = URI('http://socialclub.rockstargames.com/games/gtav/ajax/stockdetail') | |
http = Net::HTTP.new(uri.host, uri.port) | |
req = Net::HTTP::Get.new(uri) | |
headers.each do |name, value| | |
req.add_field(name, value) | |
end | |
res = http.request(req) | |
res.body | |
end | |
def headers | |
{ | |
'Accept' => 'application/json, text/javascript, */*; q=0.01', | |
'X-Requested-With' => 'XMLHttpRequest', | |
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5', | |
'Cookie' => 'prod=<your value>; RockStarWebSessionId=<your value>;', | |
'Referer' => 'http://socialclub.rockstargames.com/games/gtav/ps4/bawsaq' | |
} | |
end | |
response = JSON.parse(request) | |
stocks = response['Stocks'] | |
tracked = %w(Badger BitterSweet Shark Tinkle Ubermacht Whiz Zit) | |
stocks.reject! { |s| !tracked.include?(s['CompanyName']) } | |
time_format = '%-m/%-d/%y %-l:%M %p' | |
time = Time.now.strftime(time_format) | |
stock_values = stocks.map { |s| s['CurrentPrice'] }.join("\t") | |
puts "#{time}\t #{stock_values}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment