import records in batches, support w=2
[NoSQL-toys.git] / riak / load_data
1 #!/usr/bin/env escript
2 %% -*- erlang -*-
3 main([Filename]) ->
4     {ok, Data} = file:read_file(Filename),
5     Lines = tl(re:split(Data, "\r?\n", [{return, binary},trim])),
6     lists:foreach(fun(L) -> LS = re:split(L, ","), format_and_insert(LS) end, Lines).
7
8 format_and_insert(Line) ->
9     JSON = io_lib:format("{\"Date\":\"~s\",\"Open\":~s,\"High\":~s,\"Low\":~s,\"Close\":~s,\"Volume\":~s,\"Adj. Close\":~s}", Line),
10     Command = io_lib:format("curl -X PUT http://192.168.1.200:8098/riak/goog/~s -d '~s' -H 'content-type: application/json'", [hd(Line),JSON]),
11     io:format("Inserting: ~s~n", [hd(Line)]),
12     os:cmd(Command).