diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-02-23 10:35:22 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-02-23 10:35:22 +0100 |
| commit | 4abcce013c9ee3053badf2abda77190233066676 (patch) | |
| tree | 450de7e8fed3c3c7501a9d2e2eb60a676bdfa09e /_posts/notes/2023-05-23-parse-rss-with-lua.md | |
| parent | cdf50cb2e3051200c6ea0628c318d66220b7d1a1 (diff) | |
| download | mitjafelicijan.com-4abcce013c9ee3053badf2abda77190233066676.tar.gz | |
Testing thoughts page
Diffstat (limited to '_posts/notes/2023-05-23-parse-rss-with-lua.md')
| -rw-r--r-- | _posts/notes/2023-05-23-parse-rss-with-lua.md | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/_posts/notes/2023-05-23-parse-rss-with-lua.md b/_posts/notes/2023-05-23-parse-rss-with-lua.md new file mode 100644 index 0000000..ea8ce8c --- /dev/null +++ b/_posts/notes/2023-05-23-parse-rss-with-lua.md | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | --- | ||
| 2 | title: Parse RSS feeds with Lua | ||
| 3 | permalink: /parse-rss-with-lua.html | ||
| 4 | date: 2023-05-23T12:00:00+02:00 | ||
| 5 | layout: post | ||
| 6 | type: note | ||
| 7 | draft: false | ||
| 8 | tags: [lua, rss] | ||
| 9 | --- | ||
| 10 | |||
| 11 | Example 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 | ||
| 17 | local http = require("socket.http") | ||
| 18 | local feedparser = require("feedparser") | ||
| 19 | |||
| 20 | local feed_url = "https://mitjafelicijan.com/index.xml" | ||
| 21 | |||
| 22 | local response, status, _ = http.request(feed_url) | ||
| 23 | if 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 | ||
| 38 | else | ||
| 39 | print("! Request failed. Status:", status) | ||
| 40 | end | ||
| 41 | ``` | ||
