aboutsummaryrefslogtreecommitdiff
path: root/_posts/2023-05-23-parse-rss-with-lua.md
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2023-11-01 22:54:27 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2023-11-01 22:54:27 +0100
commit2417a6b7603524dc5cd30d29b153f91024b9443d (patch)
tree9be5ea8e5baba96dd9159217da6badf6157fb595 /_posts/2023-05-23-parse-rss-with-lua.md
parent89ba3497f07a8ea43d209b583f39fcc286acc923 (diff)
downloadmitjafelicijan.com-2417a6b7603524dc5cd30d29b153f91024b9443d.tar.gz
Move to Jekyll
Diffstat (limited to '_posts/2023-05-23-parse-rss-with-lua.md')
-rw-r--r--_posts/2023-05-23-parse-rss-with-lua.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/_posts/2023-05-23-parse-rss-with-lua.md b/_posts/2023-05-23-parse-rss-with-lua.md
new file mode 100644
index 0000000..ea8ce8c
--- /dev/null
+++ b/_posts/2023-05-23-parse-rss-with-lua.md
@@ -0,0 +1,41 @@
1---
2title: Parse RSS feeds with Lua
3permalink: /parse-rss-with-lua.html
4date: 2023-05-23T12:00:00+02:00
5layout: post
6type: note
7draft: false
8tags: [lua, rss]
9---
10
11Example of parsing RSS feeds with Lua. Before running the script install:
12
13- feedparser with `luarocks install feedparser`
14- luasocket with `luarocks install luasocket`
15
16```lua
17local http = require("socket.http")
18local feedparser = require("feedparser")
19
20local feed_url = "https://mitjafelicijan.com/index.xml"
21
22local response, status, _ = http.request(feed_url)
23if status == 200 then
24 local parsed = feedparser.parse(response)
25
26 -- Print out feed details.
27 print("> Title ", parsed.feed.title)
28 print("> Author ", parsed.feed.author)
29 print("> ID ", parsed.feed.id)
30 print("> Entries ", #parsed.entries)
31
32 for _, item in ipairs(parsed.entries) do
33 print("GUID ", item.guid)
34 print("Title ", item.title)
35 print("Link ", item.link)
36 print("Summary ", item.summary)
37 end
38else
39 print("! Request failed. Status:", status)
40end
41```