Update inspiration quotes widget

This commit is contained in:
Evgeny
2023-06-30 13:09:07 +04:00
parent ae15d0e730
commit 55aad881e2

View File

@@ -1,24 +1,28 @@
-- name = "Inspiration quotes" -- name = "Inspiration quotes"
-- description = "inspiration.goprogram.ai" -- description = "ZenQuotes.io"
-- data_source = "inspiration.goprogram.ai" -- data_source = "https://zenquotes.io/"
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "2.0"
-- foldable = "false" -- foldable = "false"
local json = require "json"
function on_alarm() function on_alarm()
http:get("https://inspiration.goprogram.ai/") http:get("https://zenquotes.io/api/random")
end end
function on_network_result(result) function on_network_result(result, code)
quote = ajson:get_value(result, "object string:quote") if code >= 200 and code < 299 then
author = ajson:get_value(result, "object string:author") res = json.decode(result)
ui:show_lines({ quote }, { author }) ui:show_lines({ res[1].q }, { res[1].a })
end
end end
function on_click() function on_click()
if quote ~= nil then if res ~= nil then
system:copy_to_clipboard(quote) system:to_clipboard(res[1].q.." - "..res[1].a)
end end
end end