Ok. As promised, the code is not pretty, but here is a start at parsing a bls api call for
a single series, which is what the current readfile() function can handle. It works but I
can foresee the code being rather fragile.
Logan
clear
set echo off
string s =
readfile("http://api.bls.gov/publicAPI/v1/timeseries/data/LAUCN04001...
sprintf q "\""
sprintf sq "\'"
sprintf nl "\n"
s = strsub(s,q,"")
s = strsub(s,"{year:",nl)
s = strsub(s," ","")
s = strsub(s,"[","")
s = strsub(s,"{","")
s = strsub(s,"]","")
s = strsub(s,"}","")
s = strsub(s,"'","")
s = strsub(s,":",",")
s = strsub(s,",period,","")
s = strsub(s,","," ")
s = strsub(s,"seriesID","obs blank blank blank ")
bundle dt
scalar i = 1
string line
scalar lcount = 0
loop while getline(s, line)
temp = strsplit(line,1)~","~strsplit(line,5)
if i > 2
sprintf ii "%d", i-2
dt.@ii = temp
temp = dt[@ii]
lcount ++
endif
i++
endloop
outfile test.csv --write
printf "%s\n", dt[1]
loop for (j = lcount; j>1; j--)
printf "%s\n", dt[$j]
endloop
outfile test.csv --close
append test.csv