update
This commit is contained in:
@@ -115,6 +115,13 @@ end
|
||||
|
||||
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 функций и структур данных;
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
-- arguments_help = "Введите список валютных пар в формате usd:rub btc:usd"
|
||||
-- arguments_default = "usd:rub eur:rub"
|
||||
|
||||
local sx = require "pl.stringx"
|
||||
local json = require "json"
|
||||
json = require "json"
|
||||
|
||||
-- constants
|
||||
local red_color = "#f44336"
|
||||
@@ -54,11 +53,11 @@ end
|
||||
|
||||
function on_dialog_action(dat)
|
||||
if dat == "" then dat = "latest" end
|
||||
get_rates(sx.replace(dat, ".", "-"), "curr")
|
||||
get_rates(dat:gsub(".", "-"), "curr")
|
||||
end
|
||||
|
||||
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)
|
||||
return os.date("%Y-%m-%d", prev_time)
|
||||
end
|
||||
@@ -71,10 +70,10 @@ function create_tab(result)
|
||||
|
||||
-- set title
|
||||
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
|
||||
local cur = sx.split(curs[idx], ":")
|
||||
local cur = curs[idx]:split(":")
|
||||
|
||||
local rate_curr1 = t_c.usd[cur[1]]
|
||||
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>"
|
||||
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
38
holydays-ru-widget.lua
Normal 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
5
print-error.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
function print_hello()
|
||||
print("HELLO")
|
||||
end
|
||||
|
||||
print_hello()
|
||||
@@ -1,5 +1,5 @@
|
||||
-- name = "News"
|
||||
-- description = "Simple news widget"
|
||||
-- description = "Simple RSS news widget"
|
||||
-- data_source = "https://rss-to-json-serverless-api.vercel.app/"
|
||||
-- type = "widget"
|
||||
-- author = "Andrey Gavrilov"
|
||||
@@ -8,7 +8,7 @@
|
||||
-- settings
|
||||
local feed = "https://news.yandex.ru/index.rss"
|
||||
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 titles = {}
|
||||
@@ -33,20 +33,18 @@ end
|
||||
function on_network_result(result)
|
||||
local t = json.decode(result)
|
||||
local 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")
|
||||
ui:show_dialog(titles[i].." | "..times[i], descs[i], "open in browser")
|
||||
end
|
||||
|
||||
function on_dialog_action(i)
|
||||
|
||||
5
utils-sample.lua
Normal file
5
utils-sample.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
function on_resume()
|
||||
local str = "one two three"
|
||||
local tab = str:split(" ")
|
||||
ui:show_text(tab[2])
|
||||
end
|
||||
24
utils.lua
24
utils.lua
@@ -12,9 +12,33 @@ function get_args_kv()
|
||||
return { keys, values }
|
||||
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)
|
||||
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
|
||||
|
||||
function table:has_value(val)
|
||||
for index, value in ipairs(self) do
|
||||
if value == val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user