Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6421810891 |
32
community/sunrise-sunset-search.lua
Normal file
32
community/sunrise-sunset-search.lua
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
-- name = "Sun Info"
|
||||||
|
-- description = "Shows Sunrise Sunset at your location"
|
||||||
|
-- data_source = "https://api.sunrise-sunset.org/"
|
||||||
|
-- type = "search"
|
||||||
|
-- author = "Sriram S V"
|
||||||
|
-- version = "1.0"
|
||||||
|
-- prefix = "sun"
|
||||||
|
-- foldable = "false"
|
||||||
|
|
||||||
|
local json = require "json"
|
||||||
|
local date = require "date"
|
||||||
|
md_colors = require("md_colors")
|
||||||
|
|
||||||
|
function on_search(input)
|
||||||
|
local location=system:location()
|
||||||
|
get_sun_info(location)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_network_result(result)
|
||||||
|
local t = json.decode(result)
|
||||||
|
local sunrise = date(t.results.sunrise):tolocal():fmt("%r")
|
||||||
|
local sunset = date(t.results.sunset):tolocal():fmt("%r")
|
||||||
|
|
||||||
|
local lines = {"Sunrise: "..sunrise, "Sunset: "..sunset}
|
||||||
|
local colors = { md_colors.orange_400, md_colors.orange_800 }
|
||||||
|
search:show_lines(lines,colors)
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_sun_info(location)
|
||||||
|
url="https://api.sunrise-sunset.org/json?lat="..location[1].."&lng="..location[2].."&date=today&formatted=1"
|
||||||
|
http:get(url)
|
||||||
|
end
|
||||||
@@ -8,13 +8,12 @@
|
|||||||
|
|
||||||
local json = require "json"
|
local json = require "json"
|
||||||
local date = require "date"
|
local date = require "date"
|
||||||
|
|
||||||
function on_alarm()
|
function on_alarm()
|
||||||
local location=system:location()
|
local location=system:location()
|
||||||
url="https://api.sunrise-sunset.org/json?lat="..location[1].."&lng="..location[2].."&date=today&formatted=1"
|
get_sun_info(location)
|
||||||
http:get(url)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function on_network_result(result)
|
function on_network_result(result)
|
||||||
local t = json.decode(result)
|
local t = json.decode(result)
|
||||||
local table = {
|
local table = {
|
||||||
@@ -23,3 +22,8 @@ function on_network_result(result)
|
|||||||
}
|
}
|
||||||
ui:show_table(table, 2)
|
ui:show_table(table, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function get_sun_info(location)
|
||||||
|
url="https://api.sunrise-sunset.org/json?lat="..location[1].."&lng="..location[2].."&date=today&formatted=1"
|
||||||
|
http:get(url)
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user