Skip to content

Instantly share code, notes, and snippets.

@nickdesaulniers
Created August 31, 2013 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdesaulniers/6396604 to your computer and use it in GitHub Desktop.
Save nickdesaulniers/6396604 to your computer and use it in GitHub Desktop.
coffee yahoo.coffee tsla 08-27-2013 08-29-2013
http = require 'http'
csv = require 'csv'
if process.argv.length is 2
url = 'http://ichart.finance.yahoo.com/table.csv?s=TSLA&a=07&b=28&c=2013&d=07&e=29&f=2013&g=d'
else if process.argv.length is 5
[_, _, symbol, start, end] = process.argv
[[a, b, c], [d, e, f]] = [start.split('-'), end.split('-')]
console.log a, b, c, d, e, f
url = "http://ichart.finance.yahoo.com/table.csv?s=#{symbol}&a=#{--a}&b=#{b}&c=#{c}&d=#{--d}&e=#{e}&f=#{f}&g=d"
else
console.log 'usage: coffee yahoo.coffee [symbol] [start date] [end date]'
process.exit 1
console.log "hitting #{url}\n"
http.get url, (res) ->
if res.statusCode is 200
console.log "#{symbol.toUpperCase()} : #{new Date()}"
csv().from(res).transform (row, rowNum) ->
console.log row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment