From cd6644ea4ddc78597934ab0ef5ba50e3c3daa927 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sat, 8 Jul 2023 23:25:41 +0200 Subject: Moved to a simpler SSG --- public/parse-rss-with-lua.html | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 public/parse-rss-with-lua.html (limited to 'public/parse-rss-with-lua.html') diff --git a/public/parse-rss-with-lua.html b/public/parse-rss-with-lua.html new file mode 100755 index 0000000..58fbe27 --- /dev/null +++ b/public/parse-rss-with-lua.html @@ -0,0 +1,35 @@ +Parse RSS feeds with Lua

Parse RSS feeds with Lua

May 23, 2023

Example of parsing RSS feeds with Lua. Before running the script install:

  • feedparser with luarocks install feedparser
  • luasocket with luarocks install luasocket
local http = require("socket.http")
+local feedparser = require("feedparser")
+
+local feed_url = "https://mitjafelicijan.com/feed.rss"
+
+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
+
\ No newline at end of file -- cgit v1.2.3