File: getstock.lua

package info (click to toggle)
sc-im 0.8.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,972 kB
  • sloc: lisp: 32,533; ansic: 19,618; yacc: 1,489; xml: 518; sh: 410; makefile: 307; sed: 4
file content (35 lines) | stat: -rw-r--r-- 699 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

local http=require'socket.http'
body,c,l,h = http.request('http://download.finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG&f=sab2b3jk')


function split(str, sep)
   local result = {}
   local regex = ("([^%s]+)"):format(sep)
   for each in str:gmatch(regex) do
      table.insert(result, each)
   end
   return result
end



function trg(c,r)

file=io.open("/tmp/log.txt", "a+")

str=sc.lgetstr(c-1,r)
file:write(string.format("%d %d \n",c,r,str))
file:flush()
--sc.lsetstr(c,r,str)
body,z,l,h = http.request('http://download.finance.yahoo.com/d/quotes.csv?s='..str..'&f=sab2b3jk')
a=split(body,',')
sc.lsetnum(c,r,a[2])
file:write(string.format("%d %d  \n",c,r))
file:write(a[2])
file:flush()


end