#!/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()