Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (41 sloc) 1.33 KB
#!/usr/bin/env ruby
# KMIKEYM current stock price and ten lowest offers available
# By Douglas Dollars / @theDoug
require 'open-uri'
require 'nokogiri'
@page = Nokogiri::HTML(open("http://www.kmikeym.com/offers"))
@current_price = @page.xpath("//*[@id='price-block-inner']/h2/text()")
def offer(number)
who = slicer(number, "/td/a")
howmany = slicer(number, "/td[2]")
priced = slicer(number, "/td[3]")
# return " #{who}: #{howmany} @ #{priced}"
return " %-13s %-3s @ #{priced}" % [ who, howmany ]
end
def slicer(number, splud)
return @page.xpath("//*[@id='body']/div/div[5]/table/tr[#{number}]#{splud}/text()")
end
def line
puts '$------------------------------------------------------$'
end
def title_card(current_price)
puts '
$$$ d$P $$$$$$$$$ $$$b d$$$
$$$ d$P $$$ $$$$b d$$$$ S T O C K
$$$ d$P $$$ $$$$$b.d$$$$$
$$$d$$K $$$$$$$b. $$$Y$$$$$P$$$ V A L U E
$$$$$$$b "Y$$b $$$ Y$$$P $$$
$$$ Y$$b $$$ $$$ Y$P $$$ D I S P L A Y
$$$ Y$$b Y$$b d$$P $$$ " $$$
$$$ Y$$b "Y$$$$P" $$$ $$$ T E R M I N A L'
line
puts " Current KmikeyM value: #{current_price}/share "
line
puts ' Lowest current offers (shares / price)'
line
end
def do_it
title_card(@current_price)
for i in 1..10 do puts offer(i) end
end
do_it