add new scripts
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
function on_resume()
|
||||
while true do end
|
||||
end
|
||||
|
||||
8
coroutines-test.lua
Normal file
8
coroutines-test.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
local co = coroutine.create(function()
|
||||
ui:show_text("Hello world!")
|
||||
end)
|
||||
|
||||
function on_resume()
|
||||
ui:set_title(coroutine.status(co))
|
||||
coroutine.resume(co)
|
||||
end
|
||||
@@ -8,6 +8,7 @@
|
||||
-- arguments_default = "usd:rub eur:rub"
|
||||
|
||||
local sx = require "pl.stringx"
|
||||
local json = require "json"
|
||||
|
||||
-- constants
|
||||
local red_color = "#f44336"
|
||||
@@ -35,7 +36,8 @@ end
|
||||
function on_network_result_curr(result)
|
||||
result_curr = result
|
||||
|
||||
local dat = ajson:get_value(result, "object string:date")
|
||||
local t = json.decode(result)
|
||||
local dat = t.date
|
||||
local prev_date = prev_date(dat)
|
||||
|
||||
get_rates(prev_date, "prev")
|
||||
@@ -55,22 +57,29 @@ function on_dialog_action(dat)
|
||||
get_rates(sx.replace(dat, ".", "-"), "curr")
|
||||
end
|
||||
|
||||
function prev_date(dat)
|
||||
local prev_date = sx.split(dat, "-")
|
||||
local prev_time = os.time{year=prev_date[1], month=prev_date[2], day=prev_date[3]} - (60*60*24)
|
||||
return os.date("%Y-%m-%d", prev_time)
|
||||
end
|
||||
|
||||
function create_tab(result)
|
||||
local result_prev = result
|
||||
local curs = aio:get_args()
|
||||
local tab = {}
|
||||
local t_c = json.decode(result_curr)
|
||||
local t_p = json.decode(result)
|
||||
|
||||
-- set title
|
||||
local dat = ajson:get_value(result_curr, "object string:date")
|
||||
local dat = t_c.date
|
||||
ui:set_title(ui:get_default_title().." "..sx.replace(dat, "-", "."))
|
||||
|
||||
for idx, pair in ipairs(curs) do
|
||||
local cur = sx.split(pair, ":")
|
||||
for idx = 1, #curs, 1 do
|
||||
local cur = sx.split(curs[idx], ":")
|
||||
|
||||
local rate_curr1 = get_rate(result_curr, cur[1])
|
||||
local rate_curr2 = get_rate(result_curr, cur[2])
|
||||
local rate_prev1 = get_rate(result_prev, cur[1])
|
||||
local rate_prev2 = get_rate(result_prev, cur[2])
|
||||
local rate_curr1 = t_c.usd[cur[1]]
|
||||
local rate_curr2 = t_c.usd[cur[2]]
|
||||
local rate_prev1 = t_p.usd[cur[1]]
|
||||
local rate_prev2 = t_p.usd[cur[2]]
|
||||
|
||||
local rate_curr = round(rate_curr2/rate_curr1, 4)
|
||||
local rate_prev = round(rate_prev2/rate_prev1, 4)
|
||||
@@ -79,24 +88,13 @@ function create_tab(result)
|
||||
local line = "1 "..string.upper(cur[1])..equals..rate_curr.." "..string.upper(cur[2])
|
||||
line = line..get_formatted_change_text(change)
|
||||
|
||||
tab[idx] = line
|
||||
table.insert(tab, line)
|
||||
end
|
||||
|
||||
return tab
|
||||
end
|
||||
|
||||
-- utils --
|
||||
|
||||
function get_prev_date(dat)
|
||||
local prev_date = sx.split(dat, "-")
|
||||
local prev_time = os.time{year=prev_date[1], month=prev_date[2], day=prev_date[3]} - (60*60*24)
|
||||
return os.date("%Y-%m-%d", prev_time)
|
||||
end
|
||||
|
||||
function get_rate(json, currency)
|
||||
return ajson:get_value(json, "object object:usd double:"..currency)
|
||||
end
|
||||
|
||||
function get_formatted_change_text(change)
|
||||
if change > 0 then
|
||||
return "<font color=\""..green_color.."\"><small> +"..change.."%</small></font>"
|
||||
|
||||
57
rss-widget.lua
Normal file
57
rss-widget.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
-- name = "News"
|
||||
-- description = "Simple news widget"
|
||||
-- data_source = "https://rss-to-json-serverless-api.vercel.app/"
|
||||
-- type = "widget"
|
||||
-- author = "Andrey Gavrilov"
|
||||
-- version = "1.0"
|
||||
|
||||
-- settings
|
||||
local feed = "https://news.yandex.ru/index.rss"
|
||||
local lines_num = 5
|
||||
local auto_folding = false
|
||||
|
||||
local api_url = "https://rss-to-json-serverless-api.vercel.app/api?feedURL="
|
||||
local titles = {}
|
||||
local descs = {}
|
||||
local urls = {}
|
||||
local times = {}
|
||||
local url = ""
|
||||
|
||||
local json = require "json"
|
||||
|
||||
function on_resume()
|
||||
if auto_folding then
|
||||
ui:set_folding_flag(true)
|
||||
ui:show_lines(titles)
|
||||
end
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
http:get(api_url..feed)
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
local t = json.decode(result)
|
||||
local n = aio:get_args()[2]
|
||||
n = math.min(lines_num, #t.items)
|
||||
|
||||
for i = 1, n, 1 do
|
||||
titles[i] = t.items[i].title
|
||||
descs[i] = t.items[i].description
|
||||
urls[i] = t.items[i].url
|
||||
times[i] = os.date("%d.%m.%Y, %H:%M",t.items[i].created/1000)
|
||||
end
|
||||
|
||||
ui:show_lines(titles)
|
||||
end
|
||||
|
||||
function on_click(i)
|
||||
url = urls[i]
|
||||
ui:show_dialog(titles[i].." | "..times[i], descs[i], "Open in browser")
|
||||
end
|
||||
|
||||
function on_dialog_action(i)
|
||||
if i == 1 then
|
||||
system:open_browser(url)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user