Created
July 15, 2015 16:23
-
-
Save allolex/dbd6194f6495473fb5c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "httparty" | |
| require "nokogiri" | |
| stock_code = ARGV[0] | |
| url = "http://finance.yahoo.com/q?s=#{stock_code}" | |
| response = HTTParty.get url | |
| dom = Nokogiri::HTML(response.body) | |
| name = dom.xpath('//*[@id="yfi_rt_quote_summary"]/div[1]/div/h2').first.content | |
| stock_price = dom.xpath("//*[@id=\"yfs_l84_#{stock_code.downcase}\"]").first.content | |
| prev_price = dom.xpath('//*[@class="yfnc_tabledata1"]').first.content | |
| ask_price = dom.xpath('//*[@class="yfnc_tabledata1"]')[3].content | |
| puts "#{name}'s stock is at #{stock_price}, but it was #{prev_price}." | |
| puts "Asking: #{ask_price}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment