From 2db6448e781a5aa92fb33c4860934278b0460777 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 30 Oct 2020 19:03:07 +1100 Subject: [PATCH] write the program --- README.md | 12 +++++++++++- mhwnews.lua | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 mhwnews.lua diff --git a/README.md b/README.md index 6d1fc3a..4676f9a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # mhwnews -Script to convert Monster Hunter World's news.json into an RSS feed \ No newline at end of file +Script to convert Monster Hunter World's news.json into an RSS feed + +## Dependencies + +- lua +- lua-cjson +- curl + +## Usage + + lua mhwnews.lua output.rss.xml diff --git a/mhwnews.lua b/mhwnews.lua new file mode 100644 index 0000000..f91cf46 --- /dev/null +++ b/mhwnews.lua @@ -0,0 +1,55 @@ +#!/usr/bin/env lua +local json = require "cjson" +local tA = {...} + +local mhwurl = tA[2] or "https://www.monsterhunter.com/world-iceborne/pc/assets/data/us/news.json" +local title = "Unofficial Monster Hunter World News" +local jsf = os.tmpname() +os.execute(string.format("curl -so '%s' '%s'",jsf,mhwurl)) +local f = io.open(jsf,"rb") +if not f then error("unable to open file for reading: "..jsf) end +local c = f:read("*a") +f:close() +os.execute(string.format("rm '%s'",jsf)) +local jt = json.decode(c) +local f = io.open(tA[1],"wb") +if not f then error("unable to open file for writing: "..tA[1]) end +f:write(string.format([[ + + + %s + https://www.monsterhunter.com/world-iceborne/pc/us/ + %s + 1440 +]], title, os.date("%a, %d %b %Y %H:%M:%S %z"))) +for k,v in pairs(jt.topics) do + if v.link:sub(1,8) ~= "https://" then + v.link = "https://www.monsterhunter.com/" .. v.link + end + local p = io.popen(string.format("curl -sI '%s' | grep last-modified",v.link)) + local c = p:read("*a") + p:close() + mdate = c:match(": ([^\r\n]+)") + if mdate then + f:write(string.format([[ + %s + + %s + %s + %s + +]], v.text, v.img, v.link, v.link, mdate)) + else + f:write(string.format([[ + %s + + %s + %s + +]], v.text, v.img, v.link, v.link)) + end +end + +f:write([[ +]]) +f:close()