29 lines
673 B
Lua
29 lines
673 B
Lua
|
#!/usr/bin/lua
|
||
|
--ngx.say(_VERSION)
|
||
|
|
||
|
local sqlite = require("lsqlite3")
|
||
|
local basepath = "/home/paul/git/micodus_server"
|
||
|
local dbfile = string.format("%s/data/tracker.db",basepath)
|
||
|
--local output = string.format("%s/html/lastloc.json",basepath)
|
||
|
local query = [[
|
||
|
SELECT latitude,longitude
|
||
|
FROM log
|
||
|
ORDER BY time DESC
|
||
|
LIMIT 1;
|
||
|
]]
|
||
|
|
||
|
function main()
|
||
|
local db = sqlite.open(dbfile,sqlite3.OPEN_READONLY)
|
||
|
|
||
|
local res, vm = db:nrows(query)
|
||
|
for row in res, vm do
|
||
|
local locstr = string.format("{\"latitude\": %s, \"longitude\": %s}", row.latitude, row.longitude)
|
||
|
--f = io.open(output, "w")
|
||
|
--f:write(locstr)
|
||
|
ngx.say(locstr)
|
||
|
end
|
||
|
db:close()
|
||
|
end
|
||
|
|
||
|
main()
|