diff -r 100a831f4f12 -r 4c3028c21ccb mcbot/cmds/tvcal.lua
--- a/mcbot/cmds/tvcal.lua Wed Feb 08 19:30:35 2012 +0100
+++ b/mcbot/cmds/tvcal.lua Sat Feb 11 12:45:17 2012 +0100
@@ -32,22 +32,25 @@
return nil, "Could not fetch calendar, please try again later!"
end
- local tabregex = '
%s*\n%s*'..
- '.-%s*\n%s*'..
- '(.-) | '
+ -- Regex for each day
+ local tabregex = ''..
+ '%s*(.-)%s* | '
- for day, tab in string.gmatch(contents, tabregex) do
- local epregex
+ -- Regex for parsing one day
+ local epregex = ''..
+ ']+>([^<]+)'.. -- Name
+ '
]+>([^<]+)'.. -- Episode
+ '
'
+
+ -- loop over all days
+ for day, daytab in string.gmatch(contents, tabregex) do
local d, m, y = day:match("^(%d+)_(%d+)_(%d%d%d%d)$")
day = string.format("%04d-%02d-%02d", y, m, d)
- epregex = ''..
- '- ]+>([^<]+)
'.. -- Name
- '- ([^<]+)
'.. -- Episode
- '
'
+ local shows = {}
- local shows = {}
- for name, ep in string.gmatch(tab, epregex) do
+ -- Loop over all episodes of a day
+ for name, ep in string.gmatch(daytab, epregex) do
name = name:gsub(""", "\""):gsub("&", "&")
name = name:gsub("<", "<"):gsub(">", ">")
name = name:gsub("'", "'")
@@ -60,6 +63,7 @@
end
tvcaldata[day] = shows
end
+
tvcaldata_timestamp = os.date("%F")
return true
end