From 2417a6b7603524dc5cd30d29b153f91024b9443d Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 1 Nov 2023 22:54:27 +0100 Subject: Move to Jekyll --- _posts/2023-05-23-parse-rss-with-lua.md | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 _posts/2023-05-23-parse-rss-with-lua.md (limited to '_posts/2023-05-23-parse-rss-with-lua.md') 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 @@ +--- +title: Parse RSS feeds with Lua +permalink: /parse-rss-with-lua.html +date: 2023-05-23T12:00:00+02:00 +layout: post +type: note +draft: false +tags: [lua, rss] +--- + +Example of parsing RSS feeds with Lua. Before running the script install: + +- feedparser with `luarocks install feedparser` +- luasocket with `luarocks install luasocket` + +```lua +local http = require("socket.http") +local feedparser = require("feedparser") + +local feed_url = "https://mitjafelicijan.com/index.xml" + +local response, status, _ = http.request(feed_url) +if status == 200 then + local parsed = feedparser.parse(response) + + -- Print out feed details. + print("> Title ", parsed.feed.title) + print("> Author ", parsed.feed.author) + print("> ID ", parsed.feed.id) + print("> Entries ", #parsed.entries) + + for _, item in ipairs(parsed.entries) do + print("GUID ", item.guid) + print("Title ", item.title) + print("Link ", item.link) + print("Summary ", item.summary) + end +else + print("! Request failed. Status:", status) +end +``` -- cgit v1.2.3