Add step-by-step tutorial

This commit is contained in:
Evgeny
2025-02-20 07:53:57 +08:00
parent b5b701ce1c
commit adfa6fad13
7 changed files with 299 additions and 0 deletions

23
samples/cat_facts.lua Normal file
View File

@@ -0,0 +1,23 @@
-- name = "Cat Facts"
-- type = "widget"
-- on_alarm is called automatically, up to once every 30 minutes, to refresh the widget.
function on_alarm()
ui:show_text("Loading a random cat fact...")
http:get("https://catfact.ninja/fact")
end
function on_network_result(body, code)
if code == 200 then
local json = require "json"
local data = json.decode(body) -- The json module converts the JSON string into a Lua table.
if data and data.fact then
ui:show_text("Random Cat Fact:\n" .. data.fact)
else
ui:show_text("Failed to retrieve a cat fact.")
end
else
ui:show_text("Error loading data. Code: " .. code)
end
end