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