Sync tvcal module (another website change...)
authorMikael Berthe <mikael@lilotux.net>
Sat, 11 Feb 2012 12:45:17 +0100
changeset 58 4c3028c21ccb
parent 57 100a831f4f12
child 59 0a39d217b80a
Sync tvcal module (another website change...)
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 = '<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("&quot;", "\""):gsub("&amp;", "&")
             name = name:gsub("&lt;", "<"):gsub("&gt;", ">")
             name = name:gsub("&#39;", "'")
@@ -60,6 +63,7 @@
         end
         tvcaldata[day] = shows
     end
+
     tvcaldata_timestamp = os.date("%F")
     return true
 end