Skip to content

Instantly share code, notes, and snippets.

@ecton
Created August 19, 2012 21:37
Show Gist options
  • Save ecton/3397891 to your computer and use it in GitHub Desktop.
Save ecton/3397891 to your computer and use it in GitHub Desktop.
EVE Api Checker v0.1
# Usage: ruby api_checker.rb id vcode > output.html
require 'rubygems'
require 'nokogiri'
require 'open-uri'
DEBUG = ENV['DEBUG'].to_i != 0
module EVE
def self.api_call(path, params)
query = params.reject{|k, v| v.nil?}.collect{|k,v| "#{k}=#{URI.escape(v)}"}.join("&")
url = "https://api.eveonline.com#{path}?#{query}"
STDERR.puts "=== Requesting #{url} ===" if DEBUG
result = Nokogiri::XML.parse(open("https://api.eveonline.com#{path}?#{query}"))
STDERR.puts result.to_xml if DEBUG
result.xpath("/eveapi/result")
end
def self.api_key_info(keyID, vCode)
api_call "/account/APIKeyInfo.xml.aspx", "keyID" => keyID, "vCode" => vCode
end
def self.character_info(keyID, vCode, characterID)
api_call "/eve/CharacterInfo.xml.aspx", "keyID" => keyID, "vCode" => vCode, "characterID" => characterID
end
def self.character_name(characterID)
api_call "/eve/CharacterName.xml.aspx", "ids" => Array(characterID).join(",")
end
def self.cache_names(ids)
@names ||= {}
missing_ids = ids.reject{|id| @names[id]}
if missing_ids.count > 0
character_name(missing_ids).xpath("rowset/row").each do |result|
@names[result['characterID']] = result['name']
end
end
end
def self.id_name(characterID)
@names ||= {}
@names[characterID] ||= character_name(characterID).xpath("rowset/row").first['name']
end
module Character
def self.contact_list(keyID, vCode, characterID)
EVE.api_call "/char/ContactList.xml.aspx", "keyID" => keyID, "vCode" => vCode, "characterID" => characterID
end
def self.contracts(keyID, vCode, characterID)
EVE.api_call "/char/Contracts.xml.aspx", "keyID" => keyID, "vCode" => vCode, "characterID" => characterID
end
def self.wallet_journal(keyID, vCode, characterID, fromID, rowCount)
EVE.api_call "/char/WalletJournal.xml.aspx", "keyID" => keyID, "vCode" => vCode, "characterID" => characterID, "fromID" => fromID, "rowCount" => rowCount
end
end
end
@associates = {}
def note_associate(characterID, associateID, reasoning, score)
@associates[characterID] ||= {}
@associates[characterID][associateID] ||= {}
@associates[characterID][associateID][reasoning] = @associates[characterID][associateID][reasoning].to_i + score
@associates['global'] ||= {}
@associates['global'][associateID] ||= {}
@associates['global'][associateID][reasoning] = @associates['global'][associateID][reasoning].to_i + score
end
def link_pilot(pilot_name)
"<a href=\"http://evewho.com/pilot/#{URI.escape(pilot_name)}\">#{pilot_name}</a>"
end
def output_associates(associates)
if associates.nil? || associates.empty?
STDOUT.write "<p>No known associates</p>\n"
else
STDOUT.write "<ul>\n"
charscores = {}
EVE.cache_names associates.keys
associates.each{|cid, reasons| charscores[cid] = reasons.values.inject{|s, i| s + i}}
associates.sort{|a, b| charscores[b[0]] <=> charscores[a[0]]}.each do |cid, reasons|
STDOUT.write "<li>#{link_pilot(EVE.id_name(cid))} - #{charscores[cid]} - #{reasons.keys.join(", ")}</li>\n"
end
STDOUT.write "</ul>\n"
end
end
keyID = ARGV[0]
vCode = ARGV[1]
keyinfo = EVE.api_key_info(keyID, vCode)
keyinfo.xpath("key/rowset/row").each do |char|
charname = char["characterName"]
characterID = char["characterID"]
STDOUT.write "<h1>#{link_pilot(charname)}</h1>\n"
contacts = EVE::Character.contact_list(keyID, vCode, characterID)
contacts.xpath("rowset[@name='contactList']").each do |contactList|
contactList.xpath("row").each do |contact|
note_associate(characterID, contact['contactID'], "Excellent Standing for #{charname}", 10) if contact['standing'].to_i == 10
note_associate(characterID, contact['contactID'], "Positive Standing for #{charname}", 5) if contact['standing'].to_i == 5
end
end
contracts = EVE::Character.contracts(keyID, vCode, characterID)
contracts.xpath("rowset/row").each do |contract|
next if contract['availability'] != 'Private' && contract['forCorp'] != '0'
note_associate(characterID, contract['issuerID'], "Received private #{contract['type']} on #{charname}", 10) if contract['assigneeID'] == characterID
note_associate(characterID, contract['assigneeID'], "Sent private #{contract['type']} on #{charname}", 10) if contract['issuerID'] == characterID
end
# Walk wallet transactions
lowest_id = nil
while true
journal = EVE::Character.wallet_journal keyID, vCode, characterID, lowest_id.to_s, "2560"
count = 0
journal.xpath("rowset/row").each do |entry|
count += 1
refId = entry['refID'].to_i
lowest_id = refId if lowest_id.nil? || refId < lowest_id
case entry['refTypeID']
when '1'
note_associate(characterID, entry['ownerID1'], "Player Trading on #{charname}", 10) if entry['ownerID2'] == characterID
note_associate(characterID, entry['ownerID2'], "Player Trading on #{charname}", 10) if entry['ownerID1'] == characterID
when '10'
note_associate(characterID, entry['ownerID1'], "Player Donation on #{charname} (#{entry['amount']} ISK - #{entry['reason']})", 10) if entry['ownerID2'] == characterID
note_associate(characterID, entry['ownerID2'], "Player Donation on #{charname} (#{entry['amount']} ISK - #{entry['reason']})", 10) if entry['ownerID1'] == characterID
end
end
break if count == 0
end
output_associates @associates[characterID]
end
STDOUT.write "<h1>Account Associates</h1>"
output_associates @associates['global']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment