Created
January 21, 2012 00:35
-
-
Save amscotti/1650445 to your computer and use it in GitHub Desktop.
Pulling a World of Warcraft guild roster in to a MongoDB
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 'nestful' | |
require 'mongo' | |
db = Mongo::Connection.new.db("wowstats") | |
coll = db.collection("character") | |
coll.drop | |
type = { | |
1 => "Warrior", 2 => "Paladin", 3 => "Hunter", | |
4 => "Rogue", 5 => "Priest", 6 => "Death Knight", | |
7 => "Shaman", 8 => "Mage", 9 => "Warlock", | |
11 => "Druid" | |
} | |
type.default = "unknown" | |
strRealm = "Lothar" | |
strGuildName = "Controlled Chaos" | |
data = Nestful.json_get "http://us.battle.net/api/wow/guild/#{URI.escape(strRealm)}/#{URI.escape(strGuildName)}?fields=members" | |
data["members"].each do |member| | |
c = member["character"] | |
doc = {:realm=>strRealm, :guild=>strGuildName, :name=>c['name'], :level=>c['level'], :class=>type[c['class']], :added=>Time.new} | |
coll.save(doc) | |
end | |
puts "#{coll.count} Characters Found!" | |
puts "-" * 50 | |
type.each_value do |type| | |
puts "#{type}" | |
puts "-" * 25 | |
coll.find({:class=>type}).sort([[:level, -1], [:name, 1]]).each do |c| | |
puts "%-20s%-10s" %[c['name'],c['level']] | |
end | |
puts "" | |
end | |
puts "-" * 50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment