scripts reorganisation

This commit is contained in:
Evgeny
2022-09-16 09:28:47 +03:00
parent c4aaa8ef30
commit 8bdb2a84a9
7 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
-- 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",
}

View File

@@ -0,0 +1,63 @@
-- 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

View File

@@ -0,0 +1,30 @@
-- name = "Password generator"
-- description = "30-character password generator"
-- type = "search"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
local pass = ""
function on_search(str)
if str:lower():find(string.lower("password")) then
pass = gen_pass()
search:show{pass}
end
end
function gen_pass()
local chars = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V','W', 'X', 'Y', 'Z', 'a','b','c','d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!', '"','#','$','%','&',"'",'(',')','*','+',',','-','.','/','1','2','3','4','5','6','7','8','9','0',':',';','<','=','>','?','@','[',']','^','_','`','{','}'}
math.randomseed(os.clock()*100000000000)
pass = ""
for i=1, 30, 1 do
pass = pass..chars[math.random(1, #chars)]
end
return pass
end
function on_click()
system:copy_to_clipboard(pass)
end

View File

@@ -0,0 +1,21 @@
-- name = "What to do?"
-- description = "Let's find you something to do"
-- data_source = "https://www.boredapi.com/"
-- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0"
-- foldable = "false"
function on_resume()
ui:show_text("Tell me what to do?")
end
function on_click()
system:vibrate(100)
http:get("http://www.boredapi.com/api/activity/")
end
function on_network_result(result)
text = ajson:get_value(result, "object string:activity")
ui:show_text(text)
end