From a42cb62064b6786fb4923e2f9a68b1d1b032eefa Mon Sep 17 00:00:00 2001 From: sriramsv Date: Tue, 13 Dec 2022 22:06:53 -0800 Subject: [PATCH 1/2] Add Sunrise Sunset Widget --- community/sunrise-sunset.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 community/sunrise-sunset.lua diff --git a/community/sunrise-sunset.lua b/community/sunrise-sunset.lua new file mode 100644 index 0000000..5f3129a --- /dev/null +++ b/community/sunrise-sunset.lua @@ -0,0 +1,25 @@ +-- name = "Sunrise/Sunset" +-- description = "Shows Sunrise Sunset at your location" +-- data_source = "https://api.sunrise-sunset.org/" +-- type = "widget" +-- author = "Sriram S V" +-- version = "1.0" +-- foldable = "false" + +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) +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 \ No newline at end of file From 471afcb14cd8c2d703afbb453acbae506d9a0f74 Mon Sep 17 00:00:00 2001 From: sriramsv Date: Thu, 22 Dec 2022 11:26:36 -0800 Subject: [PATCH 2/2] Rename --- community/{sunrise-sunset.lua => sunrise-sunset-widget.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename community/{sunrise-sunset.lua => sunrise-sunset-widget.lua} (100%) diff --git a/community/sunrise-sunset.lua b/community/sunrise-sunset-widget.lua similarity index 100% rename from community/sunrise-sunset.lua rename to community/sunrise-sunset-widget.lua