diff --git a/community/thirukkural-widget.lua b/community/thirukkural-widget.lua new file mode 100644 index 0000000..519cbd5 --- /dev/null +++ b/community/thirukkural-widget.lua @@ -0,0 +1,80 @@ +-- name = "Thirukkural" +-- description = "Thirukkural Widget that refreshes a verse form the Tamil Book Thirukkural. Single click will open the diaglog with multiple translations in English and Tamili. Long press will retrive a new verse. This uses the API from getthirukural" +-- data_source = "https://getthirukural.appspot.com/" +-- type = "widget" +-- author = "Abdul MJ (mjabdulm@gmail.com)" +-- version = "1.0" +-- foldable = "false" + +local json = require "json" +local kural_data = nil -- Store the kural translation data + +function on_alarm() + -- Fetch random kural with English translation + -- http:get("https://api.alquran.cloud/v1/ayah/random/en.sahih") + http:get("https://getthirukural.appspot.com/api/3.0/kural/rnd?appid=bzh3rnqagllov") +end + +function on_network_result(result) + local response = json.decode(result) + + if response then + -- Store kural data including athigaram name, kural number + kural_data = { + number = response.number, + line1 = response.line1, + line2 = response.line2, + paal = response.paal, + athigaram = response.athigaram, + iyal = response.iyal, + urai1Author = response.urai1Author, + urai2Author = response.urai2Author, + urai3Author = response.urai3Author, + urai1 = response.urai1, + urai2 = response.urai2, + urai3 = response.urai3, + en = response.en + } + + display_kural() + else + ui:show_message("Error loading kural data.") + end +end + +function display_kural() + if kural_data then + local display_lines = { + -- kural_data.number .. " : " .. kural_data.line1 .. "
       " .. kural_data.line2 + -- kural_data.line1 .. "
" .. kural_data.line2 .. " - " .. kural_data.number .. ":".. kural_data.athigaram .. ":" .. kural_data.paal .. "" + kural_data.line1 .. "
" .. kural_data.line2 .. " -" .. kural_data.number .. "" + -- kural_data.line1 .. "
" .. kural_data.line2 .. [[- ]] .. kural_data.number .. ":" .. kural_data.athigaram .. "" + } + + -- ui:show_lines(display_lines display_titles) + ui:show_lines(display_lines) + end +end + +function on_click() + if kural_data then + -- Prepare text to copy to clipboard with English translation only + local title = "Thirukkural:" .. kural_data.number + + local text = kural_data.number .. ":" .. kural_data.paal .. ":" .. kural_data.iyal .. ":" .. kural_data.athigaram .. "

Kural
" .. kural_data.line1 .. "
" .. kural_data.line2 .. "

English:
" .. kural_data.en .. "" .. kural_data.urai1Author .. "
" .. kural_data.urai1 .. "" .. kural_data.urai2Author .. "
" .. kural_data.urai2 .. "" .. kural_data.urai3Author .. "
" .. kural_data.urai3 + + -- system:to_clipboard(clipboard_text) + dialogs:show_dialog(title,text) + display_kural() + -- ui:show_lines(clipboard_text) + else + ui:show_message("No kural available to copy.") + end +end + +function on_long_click() + -- Fetch random kural on long-click + http:get("https://getthirukural.appspot.com/api/3.0/kural/rnd?appid=bzh3rnqagllov") +end + +