This commit is contained in:
Evgeny
2021-08-04 21:33:51 +03:00
parent 259ef63496
commit 5f893021ff
7 changed files with 87 additions and 18 deletions

View File

@@ -115,6 +115,13 @@ end
AIO Launcher включает в себя интерпретатор LuaJ 3.0.1 (совместимый с Lua 5.2) со стандартным набором библиотек: `base`, `bit32`, `coroutine`, `io`, `math`, `os`, `package`, `string`, `table`. AIO Launcher включает в себя интерпретатор LuaJ 3.0.1 (совместимый с Lua 5.2) со стандартным набором библиотек: `base`, `bit32`, `coroutine`, `io`, `math`, `os`, `package`, `string`, `table`.
Стандартный API Lua расширен следующими функциями:
* `string:split(delimeter)` - разделяет строку с помощью указанного разделителя и возвращает таблицу;
* `table:has_value(value)` - проверяет есть ли в таблице указанное значение;
* `round(x, n)` - округляет число;
* `get_args_kv()` - если аргументы скрипта записаны как "key:value key:value ..." возвращает две таблицы: ключи и значения;
В комплект также входят: В комплект также входят:
* [Penlight](http://stevedonovan.github.io/Penlight/api/manual/01-introduction.md.html) - набор портированных из Python функций и структур данных; * [Penlight](http://stevedonovan.github.io/Penlight/api/manual/01-introduction.md.html) - набор портированных из Python функций и структур данных;

View File

@@ -7,8 +7,7 @@
-- arguments_help = "Введите список валютных пар в формате usd:rub btc:usd" -- arguments_help = "Введите список валютных пар в формате usd:rub btc:usd"
-- arguments_default = "usd:rub eur:rub" -- arguments_default = "usd:rub eur:rub"
local sx = require "pl.stringx" json = require "json"
local json = require "json"
-- constants -- constants
local red_color = "#f44336" local red_color = "#f44336"
@@ -54,11 +53,11 @@ end
function on_dialog_action(dat) function on_dialog_action(dat)
if dat == "" then dat = "latest" end if dat == "" then dat = "latest" end
get_rates(sx.replace(dat, ".", "-"), "curr") get_rates(dat:gsub(".", "-"), "curr")
end end
function prev_date(dat) function prev_date(dat)
local prev_date = sx.split(dat, "-") local prev_date = dat:split("-")
local prev_time = os.time{year=prev_date[1], month=prev_date[2], day=prev_date[3]} - (60*60*24) 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) return os.date("%Y-%m-%d", prev_time)
end end
@@ -71,10 +70,10 @@ function create_tab(result)
-- set title -- set title
local dat = t_c.date local dat = t_c.date
ui:set_title(ui:get_default_title().." "..sx.replace(dat, "-", ".")) ui:set_title(ui:get_default_title().." "..dat:gsub("-", "."))
for idx = 1, #curs, 1 do for idx = 1, #curs, 1 do
local cur = sx.split(curs[idx], ":") local cur = curs[idx]:split(":")
local rate_curr1 = t_c.usd[cur[1]] local rate_curr1 = t_c.usd[cur[1]]
local rate_curr2 = t_c.usd[cur[2]] local rate_curr2 = t_c.usd[cur[2]]
@@ -104,10 +103,3 @@ function get_formatted_change_text(change)
return "<font color=\""..text_color.."\"><small> "..change.."%</small></font>" return "<font color=\""..text_color.."\"><small> "..change.."%</small></font>"
end end
end end
function round(x, n)
local n = math.pow(10, n or 0)
local x = x * n
if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end
return x / n
end

38
holydays-ru-widget.lua Normal file
View File

@@ -0,0 +1,38 @@
-- name = "Праздники"
-- description = "Виджет отображает предстоящие праздники."
-- data_source = "https://date.nager.at/"
-- type = "widget"
-- author = "Andrey Gavrilov"
-- version = "1.0"
--API--
local api_url = "https://date.nager.at/api/v3/NextPublicHolidays/RU"
--Настройка автосворачивания виджета--
local auto_folding = false
local lines = {}
local json = require "json"
local sx = require "pl.stringx"
function on_resume()
if auto_folding then
ui:set_folding_flag(true)
ui:show_lines(lines)
end
end
function on_alarm()
http:get(api_url)
end
function on_network_result(result)
local t = json.decode(result)
for i = 1, #t, 1 do
local date = sx.replace(t[i].date, "-", ".")
local name = t[i].localName
lines[i] = date.." - "..name
end
ui:show_lines(lines)
end

5
print-error.lua Normal file
View File

@@ -0,0 +1,5 @@
function print_hello()
print("HELLO")
end
print_hello()

View File

@@ -1,5 +1,5 @@
-- name = "News" -- name = "News"
-- description = "Simple news widget" -- description = "Simple RSS news widget"
-- data_source = "https://rss-to-json-serverless-api.vercel.app/" -- data_source = "https://rss-to-json-serverless-api.vercel.app/"
-- type = "widget" -- type = "widget"
-- author = "Andrey Gavrilov" -- author = "Andrey Gavrilov"
@@ -8,7 +8,7 @@
-- settings -- settings
local feed = "https://news.yandex.ru/index.rss" local feed = "https://news.yandex.ru/index.rss"
local lines_num = 5 local lines_num = 5
local auto_folding = false local auto_folding = true
local api_url = "https://rss-to-json-serverless-api.vercel.app/api?feedURL=" local api_url = "https://rss-to-json-serverless-api.vercel.app/api?feedURL="
local titles = {} local titles = {}
@@ -33,20 +33,18 @@ end
function on_network_result(result) function on_network_result(result)
local t = json.decode(result) local t = json.decode(result)
local n = math.min(lines_num, #t.items) local n = math.min(lines_num, #t.items)
for i = 1, n, 1 do for i = 1, n, 1 do
titles[i] = t.items[i].title titles[i] = t.items[i].title
descs[i] = t.items[i].description descs[i] = t.items[i].description
urls[i] = t.items[i].url urls[i] = t.items[i].url
times[i] = os.date("%d.%m.%Y, %H:%M",t.items[i].created/1000) times[i] = os.date("%d.%m.%Y, %H:%M",t.items[i].created/1000)
end end
ui:show_lines(titles) ui:show_lines(titles)
end end
function on_click(i) function on_click(i)
url = urls[i] url = urls[i]
ui:show_dialog(titles[i].." | "..times[i], descs[i], "Open in browser") ui:show_dialog(titles[i].." | "..times[i], descs[i], "open in browser")
end end
function on_dialog_action(i) function on_dialog_action(i)

5
utils-sample.lua Normal file
View File

@@ -0,0 +1,5 @@
function on_resume()
local str = "one two three"
local tab = str:split(" ")
ui:show_text(tab[2])
end

View File

@@ -12,9 +12,33 @@ function get_args_kv()
return { keys, values } return { keys, values }
end end
function string:split(sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(self, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function round(x, n) function round(x, n)
local n = math.pow(10, n or 0) local n = math.pow(10, n or 0)
local x = x * n local x = x * n
if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end
return x / n return x / n
end end
function table:has_value(val)
for index, value in ipairs(self) do
if value == val then
return true
end
end
return false
end