aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/rss.lua
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-06-09 14:38:00 +0000
committerterminaldweller <devi@terminaldweller.com>2024-06-09 14:38:00 +0000
commit309de82960b717f61dd90b908c2c28955955f504 (patch)
tree4a9a6997e25383e555200084e3835358edeb3701 /plugins/rss.lua
parentupdated the readme, remove girc.Client as an arg to the lua extension functio... (diff)
downloadmilla-309de82960b717f61dd90b908c2c28955955f504.tar.gz
milla-309de82960b717f61dd90b908c2c28955955f504.zip
added a load and unload command for plugins
Diffstat (limited to '')
-rw-r--r--plugins/rss.lua42
1 files changed, 39 insertions, 3 deletions
diff --git a/plugins/rss.lua b/plugins/rss.lua
index b78329f..aa9c757 100644
--- a/plugins/rss.lua
+++ b/plugins/rss.lua
@@ -1,3 +1,5 @@
+#!/usr/bin/env lua5.1
+
local milla = require("milla")
local yaml = require("yaml")
local http = require("http")
@@ -10,9 +12,15 @@ local function read_file(file)
return content
end
-local function get_rss_feed()
+local function sleep(n) os.execute("sleep " .. tonumber(n)) end
+
+local function get_config()
local yaml_config = read_file("./plugins/rss.yaml")
local config = yaml.parse(yaml_config)
+ return config
+end
+
+local function get_rss_feed(config)
local titles = {}
local author_names = {}
local uris = {}
@@ -20,25 +28,48 @@ local function get_rss_feed()
for _, v in pairs(config.rssfeeds) do
local response, err = http.request("GET", v.url)
+ if err ~= nil then
+ milla.send_message(err, "")
+ goto continue
+ end
local node, err = xmlpath.loadxml(response.body)
+ if err ~= nil then
+ milla.send_message(err, "")
+ goto continue
+ end
local path, err = xmlpath.compile("//entry/title")
+ if err ~= nil then
+ milla.send_message(err, "")
+ goto continue
+ end
local iterator = path:iter(node)
for _, match in ipairs(iterator) do
table.insert(titles, match:string())
end
path, err = xmlpath.compile("//entry/author/name")
+ -- local path, err = xmlpath.compile("//entry/title")
+ if err ~= nil then
+ milla.send_message(err, "")
+ goto continue
+ end
iterator = path:iter(node)
for _, match in ipairs(iterator) do
table.insert(author_names, match:string())
end
path, err = xmlpath.compile("//entry/author/uri")
+ -- local path, err = xmlpath.compile("//entry/title")
+ if err ~= nil then
+ milla.send_message(err, "")
+ goto continue
+ end
iterator = path:iter(node)
for _, match in ipairs(iterator) do
table.insert(uris, match:string())
end
+ ::continue::
end
for i = 1, #titles do
@@ -50,8 +81,13 @@ local function get_rss_feed()
end
local function rss_feed()
- local rss_feeds = get_rss_feed()
- for _, v in pairs(rss_feeds) do milla.send_message(v, "#rssfeed") end
+ local config = get_config()
+ while true do
+ for _, v in pairs(get_rss_feed(config)) do
+ milla.send_message(v, config.channel)
+ sleep(config.period)
+ end
+ end
end
rss_feed()