Move useless scripts to samples
This commit is contained in:
@@ -4,38 +4,40 @@
|
||||
-- type = "search"
|
||||
-- lang = "ru"
|
||||
-- author = "Andrey Gavrilov"
|
||||
-- version = "1.0"
|
||||
|
||||
local num = ""
|
||||
-- version = "1.1"
|
||||
|
||||
function on_search(input)
|
||||
num = input:match("^n (.+)")
|
||||
local num = input:match("^(+?7?%d%d%d%d%d%d%d%d%d%d+)$")
|
||||
if not num then
|
||||
return
|
||||
end
|
||||
search:show({"Оператор "..num})
|
||||
show_operator(num)
|
||||
end
|
||||
|
||||
function on_click()
|
||||
function show_operator(num)
|
||||
local json = require "json"
|
||||
local uri = "http://rosreestr.subnets.ru/?get=num&format=json&num=" .. num:gsub("%D", "")
|
||||
http:get(uri)
|
||||
return false
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
local json = require "json"
|
||||
local t = json.decode(result)
|
||||
if not t.error then
|
||||
if not t["0"].country then
|
||||
if not t["0"].moved2operator then
|
||||
search:show({t["0"].operator, t["0"].region})
|
||||
local tab = {}
|
||||
local result = shttp:get(uri)
|
||||
if not result.error then
|
||||
local t = json.decode(result.body)
|
||||
if not t.error then
|
||||
if not t["0"].country then
|
||||
if not t["0"].moved2operator then
|
||||
table.insert(tab, t["0"].operator)
|
||||
else
|
||||
table.insert(tab, t["0"].moved2operator)
|
||||
end
|
||||
table.insert(tab, t["0"].region)
|
||||
else
|
||||
search:show({t["0"].moved2operator, t["0"].region})
|
||||
table.insert(tab, t["0"].country)
|
||||
table.insert(tab, t["0"].description)
|
||||
end
|
||||
else
|
||||
search:show({t["0"].country, t["0"].description})
|
||||
table.insert(tab, t.error)
|
||||
end
|
||||
else
|
||||
search:show({t.error})
|
||||
table.insert(tab, result.error)
|
||||
end
|
||||
search:show_lines({table.concat(tab, ", ")}, {aio:colors().button})
|
||||
end
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
-- name = "Currencies"
|
||||
-- description = "Currency rates widget. Click on the date to change it."
|
||||
-- data_source = "github.com/fawazahmed0/currency-api#readme"
|
||||
-- type = "widget"
|
||||
-- author = "Andrey Gavrilov"
|
||||
-- version = "1.0"
|
||||
-- arguments_help = "Enter the list of currency pairs in the format usd:rub btc:usd"
|
||||
-- arguments_default = "usd:rub eur:rub"
|
||||
|
||||
json = require "json"
|
||||
|
||||
-- constants
|
||||
local red_color = "#f44336"
|
||||
local green_color = "#48ad47"
|
||||
local text_color = ui:get_colors().secondary_text
|
||||
local equals = "<font color=\""..text_color.."\"> = </font>"
|
||||
|
||||
-- global vars
|
||||
local result_curr = ""
|
||||
local tabl = {}
|
||||
|
||||
function on_resume()
|
||||
ui:set_folding_flag(true)
|
||||
ui:show_lines(tabl)
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
get_rates("latest", "curr")
|
||||
end
|
||||
|
||||
function get_rates(loc_date,id)
|
||||
http:get("https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/"..loc_date.."/currencies/usd.json",id)
|
||||
end
|
||||
|
||||
function on_network_result_curr(result)
|
||||
result_curr = result
|
||||
|
||||
local t = json.decode(result)
|
||||
local dat = t.date
|
||||
local prev_date = prev_date(dat)
|
||||
|
||||
get_rates(prev_date, "prev")
|
||||
end
|
||||
|
||||
function on_network_result_prev(result)
|
||||
tabl = create_tab(result)
|
||||
ui:show_lines(tabl)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
ui:show_edit_dialog("Enter the date", "Enter the date in the format 2020.12.31. A blank value is the current date.")
|
||||
end
|
||||
|
||||
function on_dialog_action(dat)
|
||||
if dat == "" then dat = "latest" end
|
||||
get_rates(dat:gsub(".", "-"), "curr")
|
||||
end
|
||||
|
||||
function prev_date(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
|
||||
|
||||
function create_tab(result)
|
||||
local curs = settings:get()
|
||||
local tab = {}
|
||||
local t_c = json.decode(result_curr)
|
||||
local t_p = json.decode(result)
|
||||
|
||||
-- set title
|
||||
local dat = t_c.date
|
||||
ui:set_title(ui:get_default_title().." "..dat:gsub("-", "."))
|
||||
|
||||
for idx = 1, #curs, 1 do
|
||||
local cur = curs[idx]:split(":")
|
||||
|
||||
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)
|
||||
local change = round((rate_curr-rate_prev)/rate_prev*100,2)
|
||||
|
||||
local line = "1 "..string.upper(cur[1])..equals..rate_curr.." "..string.upper(cur[2])
|
||||
line = line..get_formatted_change_text(change)
|
||||
|
||||
table.insert(tab, line)
|
||||
end
|
||||
return tab
|
||||
end
|
||||
|
||||
-- utils --
|
||||
|
||||
function get_formatted_change_text(change)
|
||||
if change > 0 then
|
||||
return "<font color=\""..green_color.."\"><small> +"..change.."%</small></font>"
|
||||
elseif change < 0 then
|
||||
return "<font color=\""..red_color.."\"><small> "..change.."%</small></font>"
|
||||
else
|
||||
return "<font color=\""..text_color.."\"><small> "..change.."%</small></font>"
|
||||
end
|
||||
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",
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
-- name = "Курс валюты"
|
||||
-- description = "Виджет курса валюты. Нажмите на виджет, чтобы изменить валюту. Базовая валюта и дата меняются в контекстном меню."
|
||||
-- data_source = "https://exchangerate.host/"
|
||||
-- type = "widget"
|
||||
-- author = "Andrey Gavrilov"
|
||||
-- version = "2.0"
|
||||
-- lang = "ru"
|
||||
|
||||
local json = require "json"
|
||||
local color = require "md_colors"
|
||||
local text_color = ui:get_colors().secondary_text
|
||||
local equals = "<font color=\""..text_color.."\"> = </font>"
|
||||
|
||||
-- константы --
|
||||
local curs = {"usd", "eur", "gbp", "chf", "aed", "cny", "inr", "btc", "other"}
|
||||
local curs_n = {"Доллар США", "Евро", "Фунт стерлингов", "Швейцарский франк", "Дирхам ОАЭ", "Китайский юань", "Индийская рупия", "Биткойн", "Другая"}
|
||||
local base_curs = {"rub", "usd", "other_b"}
|
||||
local base_curs_n = {"Российский рубль", "Доллар США", "Другая"}
|
||||
|
||||
-- переменные --
|
||||
local dialog_id = ""
|
||||
local cur_idx = 1
|
||||
local cur = curs[cur_idx]
|
||||
local base_cur_idx = 1
|
||||
local base_cur = base_curs[base_cur_idx]
|
||||
local date = ""
|
||||
local line = ""
|
||||
local tab = {}
|
||||
local amount = "1"
|
||||
local rate = 0
|
||||
|
||||
function on_alarm()
|
||||
date = os.date("%Y-%m-%d")
|
||||
get_rates(date)
|
||||
end
|
||||
|
||||
function get_rates(date)
|
||||
http:get("https://api.exchangerate.host/fluctuation?start_date="..prev_date(date).."&end_date="..date.."&symbols="..string.upper(base_cur).."&base="..string.upper(cur).."&amount="..amount)
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
t = json.decode(result)
|
||||
if t.rates[string.upper(base_cur)].end_rate == nil then
|
||||
date = prev_date(date)
|
||||
get_rates(date)
|
||||
return
|
||||
end
|
||||
rate = round(t.rates[string.upper(base_cur)].end_rate,4)
|
||||
local change = round(-t.rates[string.upper(base_cur)].change_pct*100,2)
|
||||
line = amount.." "..string.upper(cur).." "..equals.." "..divide_number(rate," ").." "..string.upper(base_cur)..get_formatted_change_text(change)
|
||||
tab = {{"ᐊ", amount, string.upper(cur), equals, divide_number(rate," "), string.upper(base_cur), get_formatted_change_text(change), "ᐅ"}}
|
||||
ui:show_table(tab, 7)
|
||||
ui:set_title(ui:get_default_title().." ("..date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1")..")")
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == 1 then
|
||||
date = prev_date(date)
|
||||
get_rates(date)
|
||||
ui:show_toast("Загрузка")
|
||||
elseif idx == 2 then
|
||||
dialog_id ="amount"
|
||||
ui:show_edit_dialog("Введите количество", "", amount)
|
||||
elseif idx == 3 then
|
||||
dialog_id = "cur"
|
||||
ui:show_radio_dialog("Выберите валюту", curs_n, cur_idx)
|
||||
elseif idx == 6 then
|
||||
dialog_id = "base_cur"
|
||||
ui:show_radio_dialog("Выберите базовую валюту", base_curs_n, base_cur_idx)
|
||||
elseif idx == 8 then
|
||||
date = next_date(date)
|
||||
get_rates(date)
|
||||
ui:show_toast("Загрузка")
|
||||
else
|
||||
dialog_id = "date"
|
||||
ui:show_edit_dialog("Введите дату курса", "Формат даты - 31.12.2020. Пустое значение - текущая дата", date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1"))
|
||||
end
|
||||
end
|
||||
|
||||
function on_long_click(idx)
|
||||
item_idx = idx
|
||||
|
||||
ui:show_context_menu({
|
||||
{"share-alt","Поделиться"},
|
||||
{"copy","Копировать"},
|
||||
{"redo","Перезагрузить"}
|
||||
})
|
||||
end
|
||||
|
||||
function on_dialog_action(data)
|
||||
if data == -1 then
|
||||
return
|
||||
end
|
||||
if dialog_id == "date" then
|
||||
if get_date(date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1")) == get_date(data) then
|
||||
return
|
||||
end
|
||||
date = get_date(data)
|
||||
elseif dialog_id == "cur" then
|
||||
if data == cur_idx and cur == curs[data] then
|
||||
return
|
||||
end
|
||||
cur_idx = data
|
||||
if curs[data] == "other" then
|
||||
dialog_id = "other"
|
||||
ui:show_edit_dialog("Введите валюту", "", string.lower(cur))
|
||||
return
|
||||
end
|
||||
cur = string.upper(curs[data])
|
||||
elseif dialog_id == "base_cur" then
|
||||
if data == base_cur_idx and base_cur == base_curs[data] then
|
||||
return
|
||||
end
|
||||
base_cur_idx = data
|
||||
if base_curs[data] == "other_b" then
|
||||
dialog_id = "other_b"
|
||||
ui:show_edit_dialog("Введите базовую валюту", "", string.lower(base_cur))
|
||||
return
|
||||
end
|
||||
base_cur = string.upper(base_curs[data])
|
||||
elseif dialog_id == "other" then
|
||||
if data == cur then
|
||||
return
|
||||
end
|
||||
cur = string.upper(data)
|
||||
elseif dialog_id == "other_b" then
|
||||
if data == base_cur then
|
||||
return
|
||||
end
|
||||
base_cur = string.upper(data)
|
||||
elseif dialog_id == "amount" then
|
||||
if amount == data:gsub(",",".") then
|
||||
return
|
||||
end
|
||||
amount = data:gsub(",","."):gsub("-","")
|
||||
if amount == "" then
|
||||
amount = "1"
|
||||
end
|
||||
end
|
||||
get_rates(date)
|
||||
end
|
||||
|
||||
function on_context_menu_click(menu_idx)
|
||||
if menu_idx == 2 then
|
||||
system:copy_to_clipboard(rate)
|
||||
elseif menu_idx == 1 then
|
||||
system:share_text(date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1").." "..line:gsub("(.+)<.+>(.+)<.+>(.+)<.+>(.+)<.+>", "%1%2%3%4"))
|
||||
elseif menu_idx == 3 then
|
||||
cur_idx = 1
|
||||
cur = string.upper(curs[cur_idx])
|
||||
base_cur_idx = 1
|
||||
base_cur = string.upper(base_curs[base_cur_idx])
|
||||
amount = "1"
|
||||
get_rates(os.date("%Y-%m-%d"))
|
||||
ui:show_toast("Начальные установки")
|
||||
end
|
||||
end
|
||||
|
||||
-- утилиты --
|
||||
function get_formatted_change_text(change)
|
||||
if change > 0 then
|
||||
return "<font color=\""..color.green_700.."\"> +"..change.."%</font>"
|
||||
elseif change < 0 then
|
||||
return "<font color=\""..color.red_A700.."\"> "..change.."%</font>"
|
||||
else
|
||||
return "<font color=\""..text_color.."\"> "..change.."%</font>"
|
||||
end
|
||||
end
|
||||
|
||||
function prev_date(date)
|
||||
local y, m, d = date:match("(%d+)-(%d+)-(%d+)")
|
||||
return os.date("%Y-%m-%d", os.time{year=y, month=m, day=d} - (60*60*24))
|
||||
end
|
||||
|
||||
function next_date(date)
|
||||
local y, m, d = date:match("(%d+)-(%d+)-(%d+)")
|
||||
return os.date("%Y-%m-%d", os.time{year=y, month=m, day=d} + (60*60*24))
|
||||
end
|
||||
|
||||
function divide_number(n, str)
|
||||
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
|
||||
return left..(num:reverse():gsub('(%d%d%d)','%1'..str):reverse())..right
|
||||
end
|
||||
|
||||
function get_date(date)
|
||||
local d, m, Y = date:match("(%d+).(%d+).(%d+)")
|
||||
local d0, m0, Y0 = os.date("%d.%m.%Y"):match("(%d+).(%d+).(%d+)")
|
||||
local time = os.time{day=d or 0, month=m or 0, year=Y or 0}
|
||||
local time0 = os.time{day=d0, month=m0, year=Y0}
|
||||
local str = string.format("%04d-%02d-%02d", Y or 0, m or 0, d or 0)
|
||||
if not (str == os.date("%Y-%m-%d", time) and time <= time0 - 24*60*60) then
|
||||
str = os.date("%Y-%m-%d")
|
||||
end
|
||||
return str
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
-- name = "Sudoku"
|
||||
-- description = "Sudoku games"
|
||||
-- type = "Game"
|
||||
-- type = "widget"
|
||||
-- author = "Andrey Gavrilov"
|
||||
-- version = "1.0"
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
-- name = "Tasker Widget Control"
|
||||
-- description = "Add or Remove widgets from Tasker"
|
||||
-- data_source = "internal"
|
||||
-- type = "widget"
|
||||
-- author = "Sriram SV"
|
||||
-- version = "1.0"
|
||||
|
||||
-- command structure
|
||||
-- cmd:script:*:add=:=<widget_name>
|
||||
-- cmd:script:*:remove=:=<widget_name>
|
||||
-- adb shell am broadcast -a ru.execbit.aiolauncher.COMMAND --es cmd "script:tasker widget control:add=:=<widget_name>" --es password <password>
|
||||
-- adb shell am broadcast -a ru.execbit.aiolauncher.COMMAND --es cmd "script:tasker widget control:remove=:=<widget_name>" --es password <password>
|
||||
function on_command(cmd)
|
||||
data = cmd:split("=:=")
|
||||
command = data[1]
|
||||
widget_name = data[2]
|
||||
if command == "add" then
|
||||
aio:add_widget(widget_name)
|
||||
elseif command == "remove" then
|
||||
aio:remove_widget(widget_name)
|
||||
end
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
ui:show_text("Use tasker tasks to add/remove widgets")
|
||||
end
|
||||
Reference in New Issue
Block a user