Em 12 de agosto de 2018, Allin escreveu:
On Sun, 12 Aug 2018, Henrique Andrade wrote:
> Dear Gretl Community,
>
> I'm trying to download and open some Banco Central do Brasil (BCB)
> data using its API and I don't know if there's a more "ellegant"
way
> to achieve that goal. Please take a look at the code I'm using now:
>
> <hansl>
> string str_csv =
>
readfile("http://api.bcb.gov.br/dados/serie/bcdata.sgs.24363/dados?formato=csv")
> # It is possible to download data using json format using this:
> # "http://api.bcb.gov.br/dados/serie/bcdata.sgs.24363/dados?formato=json"
> string str_csv = strsub(str_csv, "data", "")
> string str_csv = regsub(str_csv, "\"", "") # <--- it
doesn't work with
> the strsub function.
>
> outfile "data.csv" --quiet
> print str_csv
> end outfile
>
> open "data.csv"
> </hansl>
The following works for me using current gretl:
<hansl>
URL = \
"http://api.bcb.gov.br/dados/serie/bcdata.sgs.24363/dados?formato=csv"
string s = readfile(URL)
s = strsub(s, "data", "")
s = regsub(s, "\"", "")
# or if you prefer:
# quote = sprintf("\"")
# s = strsub(s, quote, "")
outfile bcdata.csv --quiet
print s
end outfile
open bcdata.csv
print -o
</hansl>
However, you may have an easier time accessing Banco Central do
Brasil via gretl's new dbnomics interface, since BCB is one of their
providers.
Thanks Allin! But the DB.NOMICS is not using the API from BCB :-(
Best,
Henrique