--- 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 = '<td id="d_(%d+_%d+_%d%d%d%d)" class="t?o?day"%s*>%s*\n%s*'..
- '<strong>.-</strong>%s*\n%s*'..
- '(.-)</td>'
+ -- Regex for each day
+ local tabregex = '<td id="d_(%d+_%d+_%d%d%d%d)" class="t?o?day"%s*>'..
+ '%s*(.-)%s*</td>'
- for day, tab in string.gmatch(contents, tabregex) do
- local epregex
+ -- Regex for parsing one day
+ local epregex = '<p>'..
+ '<a href=[^>]+>([^<]+)</a>'.. -- Name
+ '<br /><a href=[^>]+>([^<]+)</a>'.. -- Episode
+ '</p>'
+
+ -- 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 = '<ul class="seasep%s*%w*">'..
- '<li><a [^>]+>([^<]+)</a></li>'.. -- Name
- '<li>([^<]+)</li>'.. -- Episode
- '</ul>'
+ 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