7 archive_dir = uci.get("weathermon","process","archive_dir")
11 command = url_decode(os.getenv('QUERY_STRING'))
13 print("Content-Type: text/plain\r\n")
15 if command == "state" or command == "" or not command then
16 print(get_file_content(uci.get("weathermon","process","dump_file")))
18 elseif command == "props" then
19 print(get_file_content("/www/meteo/properties.json"))
21 elseif command == "years" then
23 local result = list_dir(archive_dir)
24 table.sort(result, function(a, b) return a > b; end)
25 print(json.encode(result))
27 elseif startswith(command,"months/") then
29 local year = string.match(command,"months/(%d+)")
30 local result = list_dir(archive_dir.."/"..year)
31 table.sort(result, function(a, b) return a > b; end)
32 print(json.encode(result))
34 elseif startswith(command,"days/") then
36 local year,month = string.match(command,"days/(%d+)/(%d+)")
37 local result = list_dir(archive_dir.."/"..year.."/"..month)
38 table.sort(result, function(a, b) return a > b; end)
39 print(json.encode(result))
41 elseif startswith(command,"sensors/") then
43 local year,month,day = string.match(command,"sensors/(%d+)/(%d+)/(%d+)")
44 local files = list_dir(archive_dir.."/"..year.."/"..month.."/"..day)
46 for key,value in pairs(files) do
47 local id, sensor, param = string.match(value,"(%w+)%.(%w+)%.(%w+).json")
49 result[#result+1] = id.."."..sensor.."."..param
53 print(json.encode(result))
55 elseif startswith(command,"list/") then
57 sensor = string.sub(command,string.len("list/")+1)
60 dir = uci.get("weathermon","process","working_dir").."/www"
64 for name in lfs.dir(dir) do
65 param=name:match(devid.."\."..sensor.."\.(%w+)\.json")
67 params[#params+1] = param
71 print(json.encode(params))
73 elseif startswith(command,"get/") then
75 sensor_path=string.sub(command,string.len("get/")+1)
76 devid,sensor,param = sensor_path:match("(%w+)/(%w+)/(.+)")
81 dir = uci.get("weathermon","process","working_dir").."/www"
85 for name in lfs.dir(dir) do
86 param=name:match(devid.."\."..sensor.."\.(%w+)\.json")
88 content = "\""..param.."\":"..get_file_content(dir.."/"..name)
92 result = result..","..content
97 print("{"..result.."}")
100 print(get_file_content(uci.get("weathermon","process","working_dir").."/www/"..devid.."."..sensor.."."..param..".json"))
103 elseif startswith(command,"get-archive/") then
105 local sensor_path=string.sub(command,string.len("get-archive/")+1)
106 local year,month,day,devid,sensor,param = sensor_path:match("(%d+)/(%d+)/(%d+)/(%w+)/(%w+)/(%w+)")
108 print(get_file_content(archive_dir.."/"..year.."/"..month.."/"..day.."/"..devid.."."..sensor.."."..param..".json"))