add many new scripts
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
-- name = "Battery info"
|
||||
|
||||
ticks = -1
|
||||
|
||||
function on_tick()
|
||||
-- Update one time per 10 seconds
|
||||
ticks = ticks + 1
|
||||
if ticks % 10 ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
ticks = 0
|
||||
|
||||
local batt_info = system:get_battery_info()
|
||||
local batt_strings = stringify_table(batt_info)
|
||||
ui:show_lines(batt_strings)
|
||||
end
|
||||
|
||||
function stringify_table(tab)
|
||||
local new_tab = {}
|
||||
|
||||
for k,v in pairs(tab) do
|
||||
table.insert(new_tab, capitalize(k)..": "..tostring(v))
|
||||
end
|
||||
|
||||
return new_tab
|
||||
end
|
||||
|
||||
function capitalize(string)
|
||||
return string:gsub("^%l", string.upper)
|
||||
end
|
||||
@@ -1,71 +0,0 @@
|
||||
-- name = "Exchange rates"
|
||||
-- description = "Shows currency rate by code"
|
||||
-- data_source = "https://api.exchangerate.host"
|
||||
-- type = "search"
|
||||
-- author = "Evgeny Zobbin & Andrey Gavrilov"
|
||||
-- version = "1.0"
|
||||
|
||||
-- modules
|
||||
local json = require "json"
|
||||
local md_color = require "md_colors"
|
||||
|
||||
-- constants
|
||||
local host = "https://api.exchangerate.host"
|
||||
local red = md_colors.red_500
|
||||
local base_currency = system:get_currency()
|
||||
|
||||
-- variables
|
||||
local req_currency = ""
|
||||
local req_amount = 1
|
||||
local result = 0
|
||||
|
||||
function on_search(inp)
|
||||
req_currency = ""
|
||||
req_amount = 1
|
||||
result = 0
|
||||
|
||||
local a,c = inp:match("^(%d*)%s?(%a%a%a)$")
|
||||
if c == nil then return end
|
||||
|
||||
req_currency = c:upper()
|
||||
|
||||
if get_index(supported, req_currency) == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if a ~= "" then
|
||||
req_amount = a
|
||||
end
|
||||
|
||||
search:show({"Exchange rate for "..req_amount.." "..req_currency},{red})
|
||||
end
|
||||
|
||||
function on_click()
|
||||
if result == 0 then
|
||||
http:get(host.."/convert?from="..req_currency.."&to="..base_currency.."&amount="..req_amount)
|
||||
return false
|
||||
else
|
||||
system:copy_to_clipboard(result)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function on_long_click()
|
||||
system:copy_to_clipboard(result)
|
||||
return true
|
||||
end
|
||||
|
||||
function on_network_result(res)
|
||||
local tab = json.decode(res)
|
||||
|
||||
if tab.success then
|
||||
search:show({tab.query.amount.." "..tab.query.from.." = "..tab.result.." "..tab.query.to}, {red})
|
||||
else
|
||||
search:show({"No data"},{red})
|
||||
end
|
||||
end
|
||||
|
||||
-- curl -s -XGET 'https://api.exchangerate.host/symbols?format=csv' | cut -d ',' -f 2 | grep -v code | sed 's/$/,/' | tr '\n' ' '
|
||||
supported = {
|
||||
"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", "CNH", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMW", "ZWL",
|
||||
}
|
||||
137
community/fifteen-widget.lua
Normal file
137
community/fifteen-widget.lua
Normal file
@@ -0,0 +1,137 @@
|
||||
ui:set_title("15 puzzle")
|
||||
|
||||
local json = require "json"
|
||||
local folded = "15 puzzle"
|
||||
|
||||
function tab_create()
|
||||
local tab_in = {"",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
|
||||
local tab_out = {}
|
||||
repeat
|
||||
local idx = math.random(1,#tab_in)
|
||||
table.insert(tab_out,tab_in[idx])
|
||||
table.remove(tab_in,idx)
|
||||
until #tab_in == 0
|
||||
return tab_out
|
||||
end
|
||||
|
||||
function tab_to_tabs(tab)
|
||||
local tab_in = tab
|
||||
local tab_out = {}
|
||||
local row = {}
|
||||
for i,v in ipairs(tab_in) do
|
||||
table.insert(row,v)
|
||||
if #row == math.sqrt(#tab) then
|
||||
table.insert(tab_out,row)
|
||||
row = {}
|
||||
end
|
||||
end
|
||||
return tab_out
|
||||
end
|
||||
|
||||
function tabs_to_tab(tab)
|
||||
local tab_in = tab
|
||||
local tab_out = {}
|
||||
for i,v in ipairs(tab_in) do
|
||||
for ii,vv in ipairs(v) do
|
||||
table.insert(tab_out,vv)
|
||||
end
|
||||
end
|
||||
return tab_out
|
||||
end
|
||||
|
||||
function tabs_to_desk(tab)
|
||||
local t = tab
|
||||
for i,v in ipairs(t) do
|
||||
table.insert(v,1,"│")
|
||||
table.insert(v,3,"│")
|
||||
table.insert(v,5,"│")
|
||||
table.insert(v,7,"│")
|
||||
table.insert(v,9,"│")
|
||||
end
|
||||
table.insert(t,1,{"┌","─","┬","─","┬","─","┬","─","┐"})
|
||||
table.insert(t,3,{"├","─","┼","─","┼","─","┼","─","┤"})
|
||||
table.insert(t,5,{"├","─","┼","─","┼","─","┼","─","┤"})
|
||||
table.insert(t,7,{"├","─","┼","─","┼","─","┼","─","┤"})
|
||||
table.insert(t,9,{"└","─","┴","─","┴","─","┴","─","┘"})
|
||||
return t
|
||||
end
|
||||
|
||||
function desk_to_tabs(tab)
|
||||
local t = tab
|
||||
table.remove(t,9)
|
||||
table.remove(t,7)
|
||||
table.remove(t,5)
|
||||
table.remove(t,3)
|
||||
table.remove(t,1)
|
||||
for i,v in ipairs(t) do
|
||||
table.remove(v,9)
|
||||
table.remove(v,7)
|
||||
table.remove(v,5)
|
||||
table.remove(v,3)
|
||||
table.remove(v,1)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
on_resume()
|
||||
end
|
||||
|
||||
function on_resume()
|
||||
if (not files:read("fifteen")) or (#json.decode(files:read("fifteen"))~=16) then
|
||||
reload()
|
||||
else
|
||||
redraw()
|
||||
end
|
||||
end
|
||||
|
||||
function redraw()
|
||||
local tab = tabs_to_desk(tab_to_tabs(json.decode(files:read("fifteen"))))
|
||||
ui:show_table(tab, 0, true, folded)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == 0 then
|
||||
ui:show_dialog("Select Action","","Cancel","Reload")
|
||||
return
|
||||
else
|
||||
local tab = tabs_to_tab(tabs_to_desk(tab_to_tabs(json.decode(files:read("fifteen")))))
|
||||
if type(tab[idx]) ~= "number" then
|
||||
return
|
||||
end
|
||||
if tab[idx-2] == "" then
|
||||
tab[idx-2] = tab[idx]
|
||||
tab[idx] = ""
|
||||
elseif tab[idx+2] == "" then
|
||||
tab[idx+2] = tab[idx]
|
||||
tab[idx] = ""
|
||||
elseif (idx-18>0) and (tab[idx-18] == "") then
|
||||
tab[idx-18] = tab[idx]
|
||||
tab[idx] = ""
|
||||
elseif (idx+18<#tab) and (tab[idx+18] == "") then
|
||||
tab[idx+18] = tab[idx]
|
||||
tab[idx] = ""
|
||||
else
|
||||
return
|
||||
end
|
||||
system:vibrate(10)
|
||||
tab = tabs_to_tab(desk_to_tabs(tab_to_tabs(tab)))
|
||||
files:write("fifteen",json.encode(tab))
|
||||
redraw()
|
||||
end
|
||||
end
|
||||
|
||||
function on_settings()
|
||||
end
|
||||
|
||||
function reload()
|
||||
local tab = tab_create()
|
||||
files:write("fifteen",json.encode(tab))
|
||||
redraw()
|
||||
end
|
||||
|
||||
function on_dialog_action(idx)
|
||||
if idx == 2 then
|
||||
reload()
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
-- name = "GitHub Trending"
|
||||
-- description = "GitHub trending repositories"
|
||||
-- data_source = "trending-github.com"
|
||||
-- type = "widget"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
http:get("https://api.trending-github.com/github/repositories")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
local names = {
|
||||
ajson:get_value(result, "array object:0 string:name"),
|
||||
ajson:get_value(result, "array object:1 string:name"),
|
||||
ajson:get_value(result, "array object:2 string:name"),
|
||||
}
|
||||
|
||||
local descriptions = {
|
||||
ajson:get_value(result, "array object:0 string:description"),
|
||||
ajson:get_value(result, "array object:1 string:description"),
|
||||
ajson:get_value(result, "array object:2 string:description"),
|
||||
}
|
||||
|
||||
urls = {
|
||||
ajson:get_value(result, "array object:0 string:url"),
|
||||
ajson:get_value(result, "array object:1 string:url"),
|
||||
ajson:get_value(result, "array object:2 string:url"),
|
||||
}
|
||||
|
||||
ui:show_lines(names, descriptions)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
system:open_browser(urls[idx])
|
||||
end
|
||||
@@ -1,63 +0,0 @@
|
||||
-- name = "Google Translate"
|
||||
-- description = "A search script that shows the translation of what you type in the search window"
|
||||
-- data_source = "translate.google.com"
|
||||
-- type = "search"
|
||||
-- author = "Evgeny Zobnin"
|
||||
-- version = "1.0"
|
||||
|
||||
local json = require "json"
|
||||
local md_color = require "md_colors"
|
||||
|
||||
-- constants
|
||||
local blue = md_colors.blue_500
|
||||
local red = md_colors.red_500
|
||||
local uri = "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto"
|
||||
|
||||
-- vars
|
||||
local text_from = ""
|
||||
local text_to = ""
|
||||
|
||||
function on_search(input)
|
||||
text_from = input
|
||||
text_to = ""
|
||||
|
||||
search:show_top({"Translate \""..input.."\""}, {blue})
|
||||
end
|
||||
|
||||
function on_click()
|
||||
if text_to == "" then
|
||||
search:show_top({"Translating..."}, {blue})
|
||||
request_trans(text_from)
|
||||
return false
|
||||
else
|
||||
system:copy_to_clipboard(text_to)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function request_trans(str)
|
||||
http:get(uri.."&tl="..system:get_lang().."&dt=t&q="..str)
|
||||
end
|
||||
|
||||
function on_network_result(result, code)
|
||||
if code >= 200 and code < 300 then
|
||||
decode_and_show(result)
|
||||
else
|
||||
search:show_top({"Server error"}, {red})
|
||||
end
|
||||
end
|
||||
|
||||
function decode_and_show(result)
|
||||
local t = json.decode(result)
|
||||
|
||||
for i, v in ipairs(t[1]) do
|
||||
text_to = text_to..v[1]
|
||||
end
|
||||
|
||||
--local lang_from = t[3]
|
||||
|
||||
if text_to ~= "" then
|
||||
search:show_top({text_to}, {blue})
|
||||
end
|
||||
end
|
||||
|
||||
141
community/region-search-ru.lua
Normal file
141
community/region-search-ru.lua
Normal file
@@ -0,0 +1,141 @@
|
||||
-- name = "Автомобильные коды"
|
||||
-- description = "Поиск по кодам автомобильных номеров России"
|
||||
-- lang = "ru"
|
||||
-- type = "search"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)
|
||||
-- version = "1.0"
|
||||
|
||||
function on_search(str)
|
||||
local code = str:match("^%d%d%d?$")
|
||||
local region = codes[code]
|
||||
|
||||
if region ~= nil then
|
||||
search:show{code.." - "..region}
|
||||
end
|
||||
end
|
||||
|
||||
codes = {
|
||||
["01"] = "Республика Адыгея",
|
||||
["02"] = "Республика Башкортостан",
|
||||
["102"] = "Республика Башкортостан",
|
||||
["03"] = "Республика Бурятия",
|
||||
["04"] = "Республика Алтай (Горный Алтай)",
|
||||
["05"] = "Республика Дагестан",
|
||||
["06"] = "Республика Ингушетия",
|
||||
["07"] = "Кабардино-Балкарская Республика",
|
||||
["08"] = "Республика Калмыкия",
|
||||
["09"] = "Республика Карачаево-Черкессия",
|
||||
["10"] = "Республика Карелия",
|
||||
["11"] = "Республика Коми",
|
||||
["12"] = "Республика Марий Эл",
|
||||
["13"] = "Республика Мордовия",
|
||||
["113"] = "Республика Мордовия",
|
||||
["14"] = "Республика Саха (Якутия)",
|
||||
["15"] = "Республика Северная Осетия — Алания",
|
||||
["16"] = "Республика Татарстан",
|
||||
["116"] = "Республика Татарстан",
|
||||
["17"] = "Республика Тыва",
|
||||
["18"] = "Удмуртская Республика",
|
||||
["19"] = "Республика Хакасия",
|
||||
["21"] = "Чувашская Республика",
|
||||
["121"] = "Чувашская Республика",
|
||||
["22"] = "Алтайский край",
|
||||
["23"] = "Краснодарский край",
|
||||
["93"] = "Краснодарский край",
|
||||
["123"] = "Краснодарский край",
|
||||
["24"] = "Красноярский край",
|
||||
["84"] = "Красноярский край",
|
||||
["88"] = "Красноярский край",
|
||||
["124"] = "Красноярский край",
|
||||
["25"] = "Приморский край",
|
||||
["125"] = "Приморский край",
|
||||
["26"] = "Ставропольский край",
|
||||
["27"] = "Хабаровский край",
|
||||
["28"] = "Амурская область",
|
||||
["29"] = "Архангельская область",
|
||||
["30"] = "Астраханская область",
|
||||
["31"] = "Белгородская область",
|
||||
["32"] = "Брянская область",
|
||||
["33"] = "Владимирская область",
|
||||
["34"] = "Волгоградская область",
|
||||
["134"] = "Волгоградская область",
|
||||
["35"] = "Вологодская область",
|
||||
["36"] = "Воронежская область",
|
||||
["37"] = "Ивановская область",
|
||||
["38"] = "Иркутская область",
|
||||
["85"] = "Иркутская область",
|
||||
["39"] = "Калининградская область",
|
||||
["91"] = "Калининградская область",
|
||||
["40"] = "Калужская область",
|
||||
["41"] = "Камчатский край",
|
||||
["42"] = "Кемеровская область",
|
||||
["43"] = "Кировская область",
|
||||
["44"] = "Костромская область",
|
||||
["45"] = "Курганская область",
|
||||
["46"] = "Курская область",
|
||||
["47"] = "Ленинградская область",
|
||||
["48"] = "Липецкая область",
|
||||
["49"] = "Магаданская область",
|
||||
["50"] = "Московская область",
|
||||
["90"] = "Московская область",
|
||||
["150"] = "Московская область",
|
||||
["190"] = "Московская область",
|
||||
["51"] = "Мурманская область",
|
||||
["52"] = "Нижегородская область",
|
||||
["152"] = "Нижегородская область",
|
||||
["53"] = "Новгородская область",
|
||||
["54"] = "Новосибирская область",
|
||||
["55"] = "Омская область",
|
||||
["56"] = "Оренбургская область",
|
||||
["57"] = "Орловская область",
|
||||
["58"] = "Пензенская область",
|
||||
["59"] = "Пермский край",
|
||||
["81"] = "Пермский край",
|
||||
["159"] = "Пермский край",
|
||||
["60"] = "Псковская область",
|
||||
["61"] = "Ростовская область",
|
||||
["161"] = "Ростовская область",
|
||||
["62"] = "Рязанская область",
|
||||
["63"] = "Самарская область",
|
||||
["163"] = "Самарская область",
|
||||
["64"] = "Саратовская область",
|
||||
["164"] = "Саратовская область",
|
||||
["65"] = "Сахалинская область",
|
||||
["66"] = "Свердловская область",
|
||||
["96"] = "Свердловская область",
|
||||
["67"] = "Смоленская область",
|
||||
["68"] = "Тамбовская область",
|
||||
["69"] = "Тверская область",
|
||||
["70"] = "Томская область",
|
||||
["71"] = "Тульская область",
|
||||
["72"] = "Тюменская область",
|
||||
["73"] = "Ульяновская область",
|
||||
["173"] = "Ульяновская область",
|
||||
["74"] = "Челябинская область",
|
||||
["174"] = "Челябинская область",
|
||||
["75"] = "Забайкальский край",
|
||||
["80"] = "Забайкальский край",
|
||||
["76"] = "Ярославская область",
|
||||
["77"] = "Москва",
|
||||
["97"] = "Москва",
|
||||
["99"] = "Москва",
|
||||
["177"] = "Москва",
|
||||
["197"] = "Москва",
|
||||
["199"] = "Москва",
|
||||
["777"] = "Москва",
|
||||
["799"] = "Москва",
|
||||
["78"] = "Санкт-Петербург",
|
||||
["98"] = "Санкт-Петербург",
|
||||
["178"] = "Санкт-Петербург",
|
||||
["79"] = "Еврейская автономная область",
|
||||
["82"] = "Республика Крым",
|
||||
["83"] = "Ненецкий автономный округ",
|
||||
["86"] = "Ханты-Мансийский автономный округ — Югра",
|
||||
["186"] = "Ханты-Мансийский автономный округ — Югра",
|
||||
["87"] = "Чукотский автономный округ",
|
||||
["89"] = "Ямало-Ненецкий автономный округ",
|
||||
["92"] = "Севастополь",
|
||||
["94"] = "Территории, находящиеся за пределами РФ и обслуживаемые Департаментом режимных объектов МВД России",
|
||||
["95"] = "Чеченская республика",
|
||||
}
|
||||
|
||||
220
community/sudoku-widget.lua
Normal file
220
community/sudoku-widget.lua
Normal file
@@ -0,0 +1,220 @@
|
||||
ui:set_title("Sudoku")
|
||||
|
||||
local json = require "json"
|
||||
local folded = "Sudoku"
|
||||
|
||||
function tab_to_tabs(tab)
|
||||
local tab_in = tab
|
||||
local tab_out = {}
|
||||
local row = {}
|
||||
for i,v in ipairs(tab_in) do
|
||||
table.insert(row,v)
|
||||
if #row == 9 then
|
||||
table.insert(tab_out,row)
|
||||
row = {}
|
||||
end
|
||||
end
|
||||
return tab_out
|
||||
end
|
||||
|
||||
function tabs_to_tab(tab)
|
||||
local tab_in = tab
|
||||
local tab_out = {}
|
||||
for i,v in ipairs(tab_in) do
|
||||
for ii,vv in ipairs(v) do
|
||||
table.insert(tab_out,vv)
|
||||
end
|
||||
end
|
||||
return tab_out
|
||||
end
|
||||
|
||||
function tabs_to_desk(tab)
|
||||
local t = tab
|
||||
for i,v in ipairs(t) do
|
||||
table.insert(v,1,"│")
|
||||
table.insert(v,5,"│")
|
||||
table.insert(v,9,"│")
|
||||
table.insert(v,13,"│")
|
||||
end
|
||||
table.insert(t,1,{"┌","─","─","─","┬","─","─","─","┬","─","─","─","┐"})
|
||||
table.insert(t,5,{"├","─","─","─","┼","─","─","─","┼","─","─","─","┤"})
|
||||
table.insert(t,9,{"├","─","─","─","┼","─","─","─","┼","─","─","─","┤"})
|
||||
table.insert(t,13,{"└","─","─","─","┴","─","─","─","┴","─","─","─","┘"})
|
||||
return t
|
||||
end
|
||||
|
||||
function desk_to_tabs(tab)
|
||||
local t = tab
|
||||
table.remove(t,13)
|
||||
table.remove(t,9)
|
||||
table.remove(t,5)
|
||||
table.remove(t,1)
|
||||
for i,v in ipairs(t) do
|
||||
table.remove(v,13)
|
||||
table.remove(v,9)
|
||||
table.remove(v,5)
|
||||
table.remove(v,1)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
on_resume()
|
||||
end
|
||||
|
||||
function on_resume()
|
||||
if (not files:read("sudoku")) or (not json.decode(files:read("sudoku")).mask) then
|
||||
reload()
|
||||
else
|
||||
redraw()
|
||||
end
|
||||
end
|
||||
|
||||
function reload()
|
||||
local sudoku = matrix_create()
|
||||
files:write("sudoku",json.encode(sudoku))
|
||||
redraw()
|
||||
end
|
||||
|
||||
function validate()
|
||||
local sudoku = json.decode(files:read("sudoku"))
|
||||
local state = "Solved"
|
||||
for i = 1, #sudoku.mask do
|
||||
if (sudoku.matrix[i] ~= sudoku.mask[i]) and (sudoku.mask[i] ~= 0) then
|
||||
state = "Wrong"
|
||||
break
|
||||
elseif sudoku.mask[i] == 0 then
|
||||
state = "Unsolved"
|
||||
end
|
||||
end
|
||||
ui:show_toast(state)
|
||||
end
|
||||
|
||||
function solve()
|
||||
local sudoku = json.decode(files:read("sudoku"))
|
||||
sudoku.mask = sudoku.matrix
|
||||
files:write("sudoku",json.encode(sudoku))
|
||||
redraw()
|
||||
end
|
||||
|
||||
function redraw()
|
||||
local tab = tabs_to_desk(tab_to_tabs(json.decode(files:read("sudoku")).mask))
|
||||
ui:show_table(tab, 0, true, folded)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == 0 then
|
||||
dialog_id = "menu"
|
||||
ui:show_radio_dialog("Select Action",{"Reload","Validate","Solve"})
|
||||
return
|
||||
end
|
||||
x = math.ceil(idx/13)
|
||||
y = idx%13
|
||||
if y == 0 then y = 13 end
|
||||
local tab = tabs_to_desk(tab_to_tabs(json.decode(files:read("sudoku")).mask))
|
||||
if type(tab[x][y]) == "number" then
|
||||
dialog_id = "number"
|
||||
ui:show_radio_dialog("Select Number",{1,2,3,4,5,6,7,8,9},tab[x][y])
|
||||
end
|
||||
end
|
||||
|
||||
function on_settings()
|
||||
end
|
||||
|
||||
function on_dialog_action(idx)
|
||||
if idx == -1 then
|
||||
return
|
||||
end
|
||||
if dialog_id == "number" then
|
||||
local sudoku = json.decode(files:read("sudoku"))
|
||||
local tab = tabs_to_desk(tab_to_tabs(sudoku.mask))
|
||||
tab[x][y] = idx
|
||||
local mask = tabs_to_tab(desk_to_tabs(tab))
|
||||
sudoku.mask = mask
|
||||
files:write("sudoku",json.encode(sudoku))
|
||||
redraw()
|
||||
elseif dialog_id == "menu" then
|
||||
if idx == 1 then
|
||||
reload()
|
||||
elseif idx == 2 then
|
||||
validate()
|
||||
elseif idx == 3 then
|
||||
solve()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function matrix_create()
|
||||
local sudoku = {}
|
||||
local t = {}
|
||||
local m = {}
|
||||
local tmp
|
||||
for i = 1, 81 do
|
||||
t[i] = 0
|
||||
end
|
||||
for i = 0, 8 do
|
||||
for j = 1, 9 do
|
||||
t[i * 9 + j] = (i * 3 + math.floor( i / 3 ) + ( j - 1) ) % 9 + 1
|
||||
end
|
||||
end
|
||||
for i = 1, 42 do
|
||||
local n1 = math.random( 9 )
|
||||
local n2
|
||||
repeat
|
||||
n2 = math.random( 9 )
|
||||
until n1 ~= n2
|
||||
for row = 0, 8 do
|
||||
for col = 1, 9 do
|
||||
if t[row * 9 + col] == n1 then
|
||||
t[row * 9 + col] = n2
|
||||
elseif(t[row * 9 + col] == n2) then
|
||||
t[row * 9 + col] = n1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for c = 1, 42 do
|
||||
local s1 = math.random( 2 )
|
||||
local s2 = math.random( 2 )
|
||||
for row = 0, 8 do
|
||||
tmp = t[row * 9 + (s1 * 3 + c % 3)]
|
||||
t[row * 9 + (s1 * 3 + c % 3)] = t[row * 9 + (s2 * 3 + c % 3)]
|
||||
t[row * 9 + (s2 * 3 + c % 3)] = tmp
|
||||
end
|
||||
end
|
||||
for s = 1, 42 do
|
||||
local c1 = math.random( 2 )
|
||||
local c2 = math.random( 2 )
|
||||
for row = 0, 8 do
|
||||
tmp = t[row * 9 + (s % 3 * 3 + c1)]
|
||||
t[row * 9 + (s % 3 * 3 + c1)] = t[row * 9 + (s % 3 * 3 + c2)]
|
||||
t[row * 9 + (s % 3 * 3 + c2)] = tmp
|
||||
end
|
||||
end
|
||||
for s = 1, 42 do
|
||||
local r1 = math.random( 2 )
|
||||
local r2 = math.random( 2 )
|
||||
for col = 1, 9 do
|
||||
tmp = t[(s % 3 * 3 + r1) * 9 + col]
|
||||
t[(s % 3 * 3 + r1) * 9 + col] = t[(s % 3 * 3 + r2) * 9 + col]
|
||||
t[(s % 3 * 3 + r2) * 9 + col] = tmp
|
||||
end
|
||||
end
|
||||
for i = 1, 81 do
|
||||
m[i] = t[i]
|
||||
end
|
||||
for i = 0, 2 do
|
||||
for j = 1, 3 do
|
||||
for k = 1, 5 do
|
||||
local c
|
||||
repeat
|
||||
c = math.random( 9 ) - 1
|
||||
until m[(i * 3 + math.floor(c / 3)) * 9 + j * 3 + c % 3] ~= 0
|
||||
m[(i * 3 + math.floor(c / 3)) * 9 + j * 3 + c % 3] = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
sudoku.matrix = t
|
||||
sudoku.mask = m
|
||||
return sudoku
|
||||
end
|
||||
90
community/tvguide-ru-widget.lua
Normal file
90
community/tvguide-ru-widget.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
-- name = "ТВ-Программа"
|
||||
-- description = "Программа передач россиийского ТВ"
|
||||
-- type = "widget"
|
||||
-- version = "1.0"
|
||||
-- lang = "ru"
|
||||
-- author = "Andrey Gavrilov"
|
||||
|
||||
local url = "https://api.peers.tv/tvguide/2/"
|
||||
local channel_id = "10338240"
|
||||
local title = "Матч ТВ"
|
||||
local tab_name,tab_time,tab_desc,tab_link,tab = {},{},{},{},{}
|
||||
local link = ""
|
||||
|
||||
function on_resume()
|
||||
ui:set_folding_flag(true)
|
||||
ui:show_table(tab,2)
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
tab_name,tab_time,tab_desc,tab_link = {},{},{},{}
|
||||
http:get(url.."schedule.json?channel="..channel_id,"schedule")
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if math.ceil(idx/2) > #tab_desc then
|
||||
ui:show_edit_dialog("Введите название канала","",title)
|
||||
else
|
||||
ui:show_dialog(tab_name[math.ceil(idx/2)].."\n"..tab_time[math.ceil(idx/2)],tab_desc[math.ceil(idx/2)],"Перейти к каналу")
|
||||
link = tab_link[math.ceil(idx/2)]
|
||||
end
|
||||
end
|
||||
|
||||
function on_network_result_channel(res)
|
||||
local json = require "json"
|
||||
local t = json.decode(res)
|
||||
if not next(t.channels[1]) then
|
||||
return
|
||||
end
|
||||
channel_id = tostring(t.channels[1].channelId)
|
||||
title = t.channels[1].title
|
||||
tab_name,tab_time,tab_desc,tab_link = {},{},{},{}
|
||||
http:get(url.."schedule.json?channel="..channel_id,"schedule")
|
||||
end
|
||||
|
||||
function on_dialog_action(data)
|
||||
if type(data) == "string" then
|
||||
http:get(url.."idbytitle.json?titles="..data,"channel")
|
||||
elseif data ~= -1 then
|
||||
system:open_browser(link)
|
||||
end
|
||||
end
|
||||
|
||||
function on_network_result_schedule(res)
|
||||
local json = require "json"
|
||||
local t = json.decode(res)
|
||||
for i,v in ipairs(t.telecastsList) do
|
||||
if os.time{year=v.date.year,month=v.date.month,day=v.date.day,hour=v.date.hour,min=v.date.minute} >= os.time() - v.duration then
|
||||
table.insert(tab_name,v.title)
|
||||
table.insert(tab_time,string.format("%02d:%02d",v.date.hour,v.date.minute))
|
||||
table.insert(tab_desc,v.description)
|
||||
table.insert(tab_link,v.URL)
|
||||
end
|
||||
if #tab_name >= 10 then
|
||||
break
|
||||
end
|
||||
end
|
||||
if #tab_name < 10 then
|
||||
http:get(url.."schedule.json?channel="..channel_id.."&dates="..os.date("%Y-%m-%d",os.time()+24*60*60),"schedule")
|
||||
return
|
||||
end
|
||||
tab = {}
|
||||
local colors = ui:get_colors()
|
||||
local row = {}
|
||||
for i,v in ipairs(tab_name) do
|
||||
local row = {}
|
||||
table.insert(row,"<font color=\""..colors.secondary_text.."\">"..tab_time[i].."</font>")
|
||||
table.insert(row,v)
|
||||
table.insert(tab,row)
|
||||
row = {}
|
||||
end
|
||||
table.insert(row," ")
|
||||
table.insert(row,"<font color=\""..colors.secondary_text.."\">Выберите канал</font>")
|
||||
table.insert(tab,row)
|
||||
ui:set_title(ui:get_default_title().." ("..title..")")
|
||||
ui:show_table(tab,2)
|
||||
end
|
||||
|
||||
function on_settings()
|
||||
return
|
||||
end
|
||||
Reference in New Issue
Block a user