Skip to content

Instantly share code, notes, and snippets.

@burke
Created September 1, 2009 04:58
Show Gist options
  • Save burke/178908 to your computer and use it in GitHub Desktop.
Save burke/178908 to your computer and use it in GitHub Desktop.
require 'date'
class EveCentral
attr_reader :item_orders
def get_new_db
`rm latest_db.dump*`
puts "--> downloading new database file..."
`curl -O 'http://eve-central.com/dumps/latest_db.dump.gz'`
puts "--> extracting database file..."
`gunzip latest_db.dump.gz`
end
def hash_ize(line)
{
:bid => (line[4].to_i == 0) ? :sell : :buy,
:price => line[5].to_f,
:vol_min => line[7].to_i,
:vol_remain => line[8].to_i,
:vol_init => line[9].to_i,
:created => DateTime.parse(line[10]),
:duration => line[11].split(' ')[0].to_i,
:reported => DateTime.parse(line[14].to_s)
}
end
def process_items(f)
puts "----> processing items..."
loop do
line = (f.readline.strip.split("\t") rescue [])
return if line.size==0
@items[line[0].to_i] = line[1]
end
end
def process_orders(f)
puts "----> processing orders... (. => 10k orders, typically ~1M total)"
i = 0
loop do
i += 1
if ((i%10000) == 0)
print '.'
$stdout.flush
end
line = f.readline
return if line.size < 10
if line[line.index("\t")+1,8] == "30000142" # Jita only
arr = (line.split("\t") rescue [])
item_id = arr[3].to_i
@orders[item_id] ||= []
@orders[item_id] << hash_ize(arr)
end
end
puts ""
end
def process_db
puts "--> processing database file..."
File.open('latest_db.dump','r') do |f|
until f.eof?
line = f.readline.strip
if line == "COPY current_market (regionid, systemid, stationid, typeid, bid, price, orderid, minvolume, volremain, volenter, issued, duration, range, reportedby, reportedtime) FROM stdin;"
process_orders(f)
elsif line == "COPY types (typeid, typename, typeclass, size, published, marketgroup, groupid, raceid) FROM stdin;"
process_items(f)
end
end
@orders.each do |k,v|
@item_orders[@items[k]] = v
end
end
end
def initialize(get_new=false)
@orders = {}
@items = {}
@item_orders = {}
get_new_db if get_new
process_db
end
end
if __FILE__ == $0
e=EveCentral.new(true)
File.open('item_orders.marshal','w'){|f|f.puts Marshal.dump(e.item_orders)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment