rendered paste body#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'rexml/document'
xml_response = Net::HTTP.get_response( URI.parse( ARGV[0] ) ).body
xml = REXML::Document.new( xml_response )
stocks = Array.new
# aggregate data
xml.elements.each( 'DBFIND/RESULT/DATA/ROW' ) do |row|
stock = Array.new
row.elements.each( 'COL' ) do |column|
case column.attributes['NAME']
when 'Symbol'
stock[0] = column.text
when 'Current_Price'
stock[1] = column.text
end
end
stocks << stock
end
# append data
ticker_log_exists = File.exists? ARGV[1]
ticker_log = File.open( ARGV[1], 'a' )
header = " DATE \t TIME \t"
row = ''
stocks.each do |stock|
header << (stock[0].center(12))
if stock[0] == "NCC"
header << " TIME"
end
header << "\t"
row << ('%12.2f' % stock[1] )
row << "\t"
if stock[0] == "NCC"
row << ( current_time.strftime('%H:%M:%S') )
row << "\t"
end
header << "\t TIME"
ticker_log.puts header unless ticker_log_exists
current_time = Time.now
ticker_log.puts "#{ current_time.strftime( '%m/%d/%Y' ) }\t#{ current_time.strftime( '%H:%M:%S' ) }\t#{ row }\t#{ current_time.strftime( '%H:%M:%S' ) }"