From c319d9e04e0906f2f3627f38454d49fa7386f070 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Mon, 23 May 2022 20:02:15 +0300 Subject: [PATCH] add bdpn-search script --- community/bdpn-search.lua | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 community/bdpn-search.lua diff --git a/community/bdpn-search.lua b/community/bdpn-search.lua new file mode 100644 index 0000000..1ce7ce1 --- /dev/null +++ b/community/bdpn-search.lua @@ -0,0 +1,41 @@ +-- name = "Мобильный оператор" +-- description = "Cкрипт отображает мобильного оператора по номеру телефона" +-- data_source = "http://rosreestr.subnets.ru/" +-- type = "search" +-- lang = "ru" +-- author = "Andrey Gavrilov" +-- version = "1.0" + +local num = "" + +function on_search(input) + num = input:match("^n (.+)") + if not num then + return + end + search:show({"Оператор "..num}) +end + +function on_click() + 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}) + else + search:show({t["0"].moved2operator, t["0"].region}) + end + else + search:show({t["0"].country, t["0"].description}) + end + else + search:show({t.error}) + end +end