From dcf5ee0982f7dbf22a8dcb05063976299216d246 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 24 May 2023 08:05:35 +0200 Subject: Note: Parsing RSS with Lua --- content/notes/non-blocking-shell-exec-csharp.md | 2 +- content/notes/parse-rss-with-lua.md | 39 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 content/notes/parse-rss-with-lua.md diff --git a/content/notes/non-blocking-shell-exec-csharp.md b/content/notes/non-blocking-shell-exec-csharp.md index 4ac3904..6de081e 100644 --- a/content/notes/non-blocking-shell-exec-csharp.md +++ b/content/notes/non-blocking-shell-exec-csharp.md @@ -1,7 +1,7 @@ --- title: Execute not blocking async shell command in C# url: non-blocking-shell-exec-csharp.html -date: 2023-05-24 +date: 2023-05-22 type: notes draft: false tags: [csharp, async, shell] diff --git a/content/notes/parse-rss-with-lua.md b/content/notes/parse-rss-with-lua.md new file mode 100644 index 0000000..9c7ca84 --- /dev/null +++ b/content/notes/parse-rss-with-lua.md @@ -0,0 +1,39 @@ +--- +title: Parse RSS feeds with Lua +url: parse-rss-with-lua.html +date: 2023-05-24 +type: notes +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/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 +``` -- cgit v1.2.3