aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-06-03 23:55:52 +0000
committerterminaldweller <devi@terminaldweller.com>2024-06-03 23:55:52 +0000
commit54510fb0c2b70aa3f4ebd00b91f25fef874f293c (patch)
tree8b8f25be96ec36744ec99eea97fea51aa8cf0d7e /plugins
parentinitial lua script support, fixes #27, fixes #34 (diff)
downloadmilla-54510fb0c2b70aa3f4ebd00b91f25fef874f293c.tar.gz
milla-54510fb0c2b70aa3f4ebd00b91f25fef874f293c.zip
updated the readme and added example for lua scripting
Diffstat (limited to 'plugins')
-rw-r--r--plugins/rss.lua57
-rw-r--r--plugins/rss.yaml7
2 files changed, 64 insertions, 0 deletions
diff --git a/plugins/rss.lua b/plugins/rss.lua
new file mode 100644
index 0000000..b78329f
--- /dev/null
+++ b/plugins/rss.lua
@@ -0,0 +1,57 @@
+local milla = require("milla")
+local yaml = require("yaml")
+local http = require("http")
+local xmlpath = require("xmlpath")
+
+local function read_file(file)
+ local f = assert(io.open(file, "rb"))
+ local content = f:read("*all")
+ f:close()
+ return content
+end
+
+local function get_rss_feed()
+ local yaml_config = read_file("./plugins/rss.yaml")
+ local config = yaml.parse(yaml_config)
+ local titles = {}
+ local author_names = {}
+ local uris = {}
+ local rss_feed_list = {}
+
+ for _, v in pairs(config.rssfeeds) do
+ local response, err = http.request("GET", v.url)
+ local node, err = xmlpath.loadxml(response.body)
+
+ local path, err = xmlpath.compile("//entry/title")
+ local iterator = path:iter(node)
+ for _, match in ipairs(iterator) do
+ table.insert(titles, match:string())
+ end
+
+ path, err = xmlpath.compile("//entry/author/name")
+ iterator = path:iter(node)
+ for _, match in ipairs(iterator) do
+ table.insert(author_names, match:string())
+ end
+
+ path, err = xmlpath.compile("//entry/author/uri")
+ iterator = path:iter(node)
+ for _, match in ipairs(iterator) do
+ table.insert(uris, match:string())
+ end
+ end
+
+ for i = 1, #titles do
+ table.insert(rss_feed_list,
+ author_names[i] .. ": " .. titles[i] .. " -- " .. uris[i])
+ end
+
+ return rss_feed_list
+end
+
+local function rss_feed()
+ local rss_feeds = get_rss_feed()
+ for _, v in pairs(rss_feeds) do milla.send_message(v, "#rssfeed") end
+end
+
+rss_feed()
diff --git a/plugins/rss.yaml b/plugins/rss.yaml
new file mode 100644
index 0000000..aee5bcf
--- /dev/null
+++ b/plugins/rss.yaml
@@ -0,0 +1,7 @@
+rssfeeds:
+ - name: "one"
+ url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCaiL2GDNpLYH6Wokkk1VNcg"
+ - name: "two"
+ url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCd26IHBHcbtxD7pUdnIgiCw"
+ - name: "three"
+ url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCS4FAVeYW_IaZqAbqhlvxlA"