Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions community/sunrise-sunset-search.lua
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions community/sunrise-sunset-widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@

local json = require "json"
local date = require "date"

function on_alarm()
local location=system:location()
url="https://api.sunrise-sunset.org/json?lat="..location[1].."&lng="..location[2].."&date=today&formatted=1"
http:get(url)
get_sun_info(location)
end


function on_network_result(result)
local t = json.decode(result)
local table = {
{ "sunrise:", date(t.results.sunrise):tolocal():fmt("%r") },
{ "sunset:", date(t.results.sunset):tolocal():fmt("%r") },
}
ui:show_table(table, 2)
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