56 lines
1.7 KiB
Lua
56 lines
1.7 KiB
Lua
#!/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([[<?xml version="1.0" encoding="UTF-8" ?>
|
|
<rss version="2.0">
|
|
<channel>
|
|
<title>%s</title>
|
|
<link>https://www.monsterhunter.com/world-iceborne/pc/us/</link>
|
|
<lastBuildDate>%s</lastBuildDate>
|
|
<ttl>1440</ttl>
|
|
]], 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([[ <item>
|
|
<title>%s</title>
|
|
<description><img src="https://www.monsterhunter.com/world-iceborne/pc/%s"></img></description>
|
|
<link>%s</link>
|
|
<guid>%s</guid>
|
|
<pubDate>%s</pubDate>
|
|
</item>
|
|
]], v.text, v.img, v.link, v.link, mdate))
|
|
else
|
|
f:write(string.format([[ <item>
|
|
<title>%s</title>
|
|
<description><img src="https://www.monsterhunter.com/world-iceborne/pc/%s"></img></description>
|
|
<link>%s</link>
|
|
<guid>%s</guid>
|
|
</item>
|
|
]], v.text, v.img, v.link, v.link))
|
|
end
|
|
end
|
|
|
|
f:write([[</channel>
|
|
</rss>]])
|
|
f:close()
|