diff --git a/defunct/covid-widget.lua b/defunct/covid-widget.lua new file mode 100644 index 0000000..41e079a --- /dev/null +++ b/defunct/covid-widget.lua @@ -0,0 +1,33 @@ +-- name = "Covid info" +-- description = "Cases of illness and death from covid" +-- data_source = "covid19api.com" +-- type = "widget" +-- author = "Evgeny Zobnin (zobnin@gmail.com)" +-- version = "1.0" + +equals = " = " + +function on_alarm() + http:get("https://api.covid19api.com/summary") +end + +function on_network_result(result, code) + if code >= 200 and code < 299 then + local new = ajson:get_value(result, "object object:Global int:NewConfirmed") + local total = ajson:get_value(result, "object object:Global int:TotalConfirmed") + local newDeaths = ajson:get_value(result, "object object:Global int:NewDeaths") + local totalDeaths = ajson:get_value(result, "object object:Global int:TotalDeaths") + + ui:show_lines({ + "Disease | total"..equals..comma_value(total).." | new"..equals..comma_value(new), + "Deaths | total"..equals..comma_value(totalDeaths).." | new"..equals..comma_value(newDeaths) + }) + end +end + +-- credit http://richard.warburton.it +function comma_value(n) + local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$') + return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right +end + diff --git a/main/covid-widget.lua b/main/covid-widget.lua deleted file mode 100644 index 626e57f..0000000 --- a/main/covid-widget.lua +++ /dev/null @@ -1,30 +0,0 @@ --- name = "Covid info" --- description = "Cases of illness and death from covid" --- data_source = "covid19api.com" --- type = "widget" --- author = "Evgeny Zobnin (zobnin@gmail.com)" --- version = "1.0" - -equals = " = " - -function on_alarm() - http:get("https://api.covid19api.com/summary") -end - -function on_network_result(result) - local new = ajson:get_value(result, "object object:Global int:NewConfirmed") - local total = ajson:get_value(result, "object object:Global int:TotalConfirmed") - local newDeaths = ajson:get_value(result, "object object:Global int:NewDeaths") - local totalDeaths = ajson:get_value(result, "object object:Global int:TotalDeaths") - - ui:show_lines({ - "Disease | total"..equals..comma_value(total).." | new"..equals..comma_value(new), - "Deaths | total"..equals..comma_value(totalDeaths).." | new"..equals..comma_value(newDeaths) - }) -end - -function comma_value(n) -- credit http://richard.warburton.it - local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$') - return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right -end - diff --git a/main/facts-widget.lua b/main/facts-widget.lua index bd30aa8..10da273 100644 --- a/main/facts-widget.lua +++ b/main/facts-widget.lua @@ -10,10 +10,11 @@ function on_alarm() http:get("https://uselessfacts.jsph.pl/random.json?language=en") end -function on_network_result(result) - text = ajson:get_value(result, "object string:text") - - ui:show_lines{ text } +function on_network_result(result, code) + if code >= 200 and code < 299 then + text = ajson:get_value(result, "object string:text") + ui:show_lines{ text } + end end function on_click() diff --git a/main/inspiration-quotes-widget.lua b/main/inspiration-quotes-widget.lua index 0297b24..4c997b6 100644 --- a/main/inspiration-quotes-widget.lua +++ b/main/inspiration-quotes-widget.lua @@ -15,7 +15,6 @@ end function on_network_result(result, code) if code >= 200 and code < 299 then res = json.decode(result) - ui:show_lines({ res[1].q }, { res[1].a }) end end diff --git a/main/public-ip-widget.lua b/main/public-ip-widget.lua index 96096ef..a08daea 100644 --- a/main/public-ip-widget.lua +++ b/main/public-ip-widget.lua @@ -10,6 +10,8 @@ function on_alarm() http:get("https://api.ipify.org") end -function on_network_result(result) - ui:show_text(result) +function on_network_result(result, code) + if code >= 200 and code < 299 then + ui:show_text(result) + end end diff --git a/main/quotes-widget.lua b/main/quotes-widget.lua index 6a2bd81..c62f6f7 100644 --- a/main/quotes-widget.lua +++ b/main/quotes-widget.lua @@ -10,11 +10,13 @@ function on_alarm() http:get("https://api.quotable.io/random") end -function on_network_result(result) - quote = ajson:get_value(result, "object string:content") - author = ajson:get_value(result, "object string:author") +function on_network_result(result, code) + if code >= 200 and code < 299 then + quote = ajson:get_value(result, "object string:content") + author = ajson:get_value(result, "object string:author") - ui:show_lines({ quote }, { author }) + ui:show_lines({ quote }, { author }) + end end function on_click() diff --git a/main/tasks-menu.lua b/main/tasks-menu.lua index 65d6383..dbdbc39 100644 --- a/main/tasks-menu.lua +++ b/main/tasks-menu.lua @@ -13,11 +13,11 @@ local primary_color = aio:colors().primary_color local secondary_color = aio:colors().secondary_color local bottom_buttons = { - "fa:note_sticky", -- notes tab - "fa:list-check", -- tasks tab - "fa:pipe", -- separator + "fa:note_sticky", -- notes tab + "fa:list-check", -- tasks tab + "fa:pipe", -- separator "fa:note_medical", -- new note button - "fa:square_plus" -- new task button + "fa:square_plus" -- new task button } local notes_list = {} diff --git a/main/wikipedia-widget.lua b/main/wikipedia-widget.lua index 5000cc9..a9c46ff 100644 --- a/main/wikipedia-widget.lua +++ b/main/wikipedia-widget.lua @@ -18,18 +18,20 @@ function on_alarm() http:get(random_url) end -function on_network_result(result) - local parsed = json.decode(result) - title = parsed.query.random[1].title - - http:get(summary_url.."&titles="..url.quote(title), "summary") +function on_network_result(result, code) + if code >= 200 and code < 299 then + local parsed = json.decode(result) + title = parsed.query.random[1].title + http:get(summary_url.."&titles="..url.quote(title), "summary") + end end -function on_network_result_summary(result) - local parsed = json.decode(result) - local extract = get_extract(parsed) - - ui:show_lines({ smart_sub(extract, 200) }, { title }) +function on_network_result_summary(result, code) + if code >= 200 and code < 299 then + local parsed = json.decode(result) + local extract = get_extract(parsed) + ui:show_lines({ smart_sub(extract, 200) }, { title }) + end end function on_click()