Skip to content

Commit 9943716

Browse files
updated the example lua script in the readme
1 parent 309de82 commit 9943716

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

README.md

+39-6
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,7 @@ rssfeeds:
558558
url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCS4FAVeYW_IaZqAbqhlvxlA"
559559
```
560560

561-
```lua
562-
local milla = require("milla")
561+
`local milla = require("milla")
563562
local yaml = require("yaml")
564563
local http = require("http")
565564
local xmlpath = require("xmlpath")
@@ -571,35 +570,64 @@ local function read_file(file)
571570
return content
572571
end
573572
574-
local function get_rss_feed()
573+
local function sleep(n) os.execute("sleep " .. tonumber(n)) end
574+
575+
local function get_config()
575576
local yaml_config = read_file("./plugins/rss.yaml")
576577
local config = yaml.parse(yaml_config)
578+
return config
579+
end
580+
581+
local function get_rss_feed(config)
577582
local titles = {}
578583
local author_names = {}
579584
local uris = {}
580585
local rss_feed_list = {}
581586
582587
for _, v in pairs(config.rssfeeds) do
583588
local response, err = http.request("GET", v.url)
589+
if err ~= nil then
590+
milla.send_message(err, "")
591+
goto continue
592+
end
584593
local node, err = xmlpath.loadxml(response.body)
594+
if err ~= nil then
595+
milla.send_message(err, "")
596+
goto continue
597+
end
585598
586599
local path, err = xmlpath.compile("//entry/title")
600+
if err ~= nil then
601+
milla.send_message(err, "")
602+
goto continue
603+
end
587604
local iterator = path:iter(node)
588605
for _, match in ipairs(iterator) do
589606
table.insert(titles, match:string())
590607
end
591608
592609
path, err = xmlpath.compile("//entry/author/name")
610+
-- local path, err = xmlpath.compile("//entry/title")
611+
if err ~= nil then
612+
milla.send_message(err, "")
613+
goto continue
614+
end
593615
iterator = path:iter(node)
594616
for _, match in ipairs(iterator) do
595617
table.insert(author_names, match:string())
596618
end
597619
598620
path, err = xmlpath.compile("//entry/author/uri")
621+
-- local path, err = xmlpath.compile("//entry/title")
622+
if err ~= nil then
623+
milla.send_message(err, "")
624+
goto continue
625+
end
599626
iterator = path:iter(node)
600627
for _, match in ipairs(iterator) do
601628
table.insert(uris, match:string())
602629
end
630+
::continue::
603631
end
604632
605633
for i = 1, #titles do
@@ -611,11 +639,16 @@ local function get_rss_feed()
611639
end
612640
613641
local function rss_feed()
614-
local rss_feeds = get_rss_feed()
615-
for _, v in pairs(rss_feeds) do milla.send_message(v, "#rssfeed") end
642+
local config = get_config()
643+
while true do
644+
for _, v in pairs(get_rss_feed(config)) do
645+
milla.send_message(v, config.channel)
646+
sleep(config.period)
647+
end
648+
end
616649
end
617650
618-
rss_feed()
651+
r``lua
619652
```
620653

621654
```lua

0 commit comments

Comments
 (0)