Created
April 1, 2012 20:01
-
-
Save amscotti/2278219 to your computer and use it in GitHub Desktop.
Using Redis to sort World of Warcraft's Auction House data. bit.ly/Hyxkq9
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
require 'rubygems' | |
require 'open-uri' | |
require 'yajl' | |
require 'redis' | |
realm = "Lothar" | |
filePath = Yajl::Parser.parse(open("http://us.battle.net/api/wow/auction/data/#{realm}"))["files"].first['url'] | |
puts filePath | |
redis = Redis.new | |
json = Yajl::Parser.parse(open(filePath)) | |
json["alliance"]["auctions"].each do |auction| | |
redis.zadd(auction["item"], auction["bid"], auction["auc"]) | |
redis.sadd("itemList", auction["item"]) | |
end | |
redis.smembers("itemList").each do |item| | |
lowest = redis.zrange(item, 0, 0).first | |
highest = redis.zrange(item, -1, -1).first | |
count = redis.zcard(item) | |
hprice = redis.zscore(item, highest).to_f/10000 | |
lprice = redis.zscore(item, lowest).to_f/10000 | |
itemName = redis.get("itemname:#{item}") | |
#puts "http://us.battle.net/api/wow/item/#{item}" if itemName.nil? | |
itemName ||= Yajl::Parser.parse(open("http://us.battle.net/api/wow/item/#{item}"))["name"] | |
redis.set("itemname:#{item}", itemName) | |
puts "Name: #{itemName}, #{count} Found: #{lprice}G to #{hprice}G" | |
end | |
redis.del("itemList") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment