mcbot/cmds/tvcal.lua
changeset 57 100a831f4f12
parent 43 7f9ecc483f73
child 58 4c3028c21ccb
equal deleted inserted replaced
56:a7c6c2b3454b 57:100a831f4f12
    31     if not contents then
    31     if not contents then
    32         return nil, "Could not fetch calendar, please try again later!"
    32         return nil, "Could not fetch calendar, please try again later!"
    33     end
    33     end
    34 
    34 
    35     local tabregex = '<td id="d_(%d+_%d+_%d%d%d%d)" class="t?o?day"%s*>%s*\n%s*'..
    35     local tabregex = '<td id="d_(%d+_%d+_%d%d%d%d)" class="t?o?day"%s*>%s*\n%s*'..
    36                      '<table>(.-)</table>'
    36                      '<strong>.-</strong>%s*\n%s*'..
       
    37                      '(.-)</td>'
    37 
    38 
    38     for day, tab in string.gmatch(contents, tabregex) do
    39     for day, tab in string.gmatch(contents, tabregex) do
    39         local epregex
    40         local epregex
    40         local d, m, y = day:match("^(%d+)_(%d+)_(%d%d%d%d)$")
    41         local d, m, y = day:match("^(%d+)_(%d+)_(%d%d%d%d)$")
    41         day = string.format("%04d-%02d-%02d", y, m, d)
    42         day = string.format("%04d-%02d-%02d", y, m, d)
    42 
    43 
    43         epregex = '<td><a id="[^"]+" href="[^"]+" class="eplink%s*%w*"%s*>([^<]+)</a>'
    44         epregex = '<ul class="seasep%s*%w*">'..
    44         epregex = epregex .. '<span class="seasep%s*%w*"%s*></span><br />'
    45                     '<li><a [^>]+>([^<]+)</a></li>'..   -- Name
    45         epregex = epregex .. '<span class="seasep%s*%w*"%s*>([^<]+)</span>[%s\n]*</td>'
    46                     '<li>([^<]+)</li>'..                -- Episode
       
    47                   '</ul>'
    46 
    48 
    47         local shows = {}
    49         local shows = {}
    48         for name, ep in string.gmatch(tab, epregex) do
    50         for name, ep in string.gmatch(tab, epregex) do
    49             name = name:gsub("&quot;", "\""):gsub("&amp;", "&")
    51             name = name:gsub("&quot;", "\""):gsub("&amp;", "&")
    50             name = name:gsub("&lt;", "<"):gsub("&gt;", ">")
    52             name = name:gsub("&lt;", "<"):gsub("&gt;", ">")