Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local url = "http://www.imperian.com/sites/all/modules/gamefeed/gamefeed-update.php"
- if feed == nil then
- feed = {
- person = "0", -- set this to your person number
- game = "imp", -- set this to your game (imp, aet, etc)
- since = nil
- }
- end
- function feed:downloadFile()
- if feed.since ~= nil then
- url = "http://www.imperian.com/sites/all/modules/gamefeed/gamefeed-update.php"
- url = url .. "?since="..feed.since.."&game="..feed.game.."&person="..feed.person
- end
- --echo("URL:"..url.."\n")
- downloadFile(getMudletHomeDir().."/feed.json", url)
- end
- local function get_timezone_offset(ts)
- local utcdate = os.date("!*t", ts)
- local localdate = os.date("*t", ts)
- --localdate.isdst = false -- this is the trick
- return os.difftime(os.time(localdate), os.time(utcdate))
- end
- local function spairs(t, order)
- -- collect the keys
- local keys = {}
- for k in pairs(t) do keys[#keys+1] = k end
- -- if order function given, sort by it by passing the table and keys a, b,
- -- otherwise just sort the keys
- if order then
- table.sort(keys, function(a,b) return order(t, a, b) end)
- else
- table.sort(keys)
- end
- -- return the iterator function
- local i = 0
- return function()
- i = i + 1
- if keys[i] then
- return keys[i], t[keys[i]]
- end
- end
- end
- function DataFeed(_, filename)
- if not filename:match("feed.json", 1, true) then return end
- local file = io.open(filename)
- local s = file:read("*all")
- file:close()
- os.remove(filename)
- local contents = yajl.to_value(s)
- local k, v
- local beginID
- if not feed.since then beginID = 0 else beginID = tonumber(feed.since) end
- for k,v in spairs(contents) do
- if tostring(v.gameid) == feed.game and tonumber(v.id) > beginID then
- local luaDate = datetime:parse(tostring(v.date),"%Y-%m-%d %H:%M:%S",true)
- luaDate = luaDate + get_timezone_offset(luaDate)
- cecho("<dark_slate_gray>[<white>" .. os.date("%Y-%m-%d %H:%M:%S",luaDate) .. "<dark_slate_gray>]<reset>\n")
- echo(tostring(v.description) .. "\n")
- end
- if feed.since ~= nil then
- if tonumber(v.id) > tonumber(feed.since) then
- feed.since = v.id
- end
- else
- feed.since = v.id
- end
- end
- contents = nil
- tempTimer(60,[[feed:downloadFile()]])
- end
- registerAnonymousEventHandler("sysDownloadDone", "DataFeed")
- feed:downloadFile()
Add Comment
Please, Sign In to add comment