3 -- $ bvvcal [bezirksname] [startdatum] [enddatum]
5 -- bezirksname : Default "friedrichshain-kreuzberg"
6 -- startdatum : in deutscher Notation (z.B. 10.10.2010), Default: heute
7 -- enddatum : Default: startdatum
9 -- Konvertiert den Berliner BVV-Sitzungskalender
10 -- ins iCalendar 2.0 (vCal) Format
13 -- - htmltidy : http://tidy.sourceforge.net/
14 -- - wget : http://www.gnu.org/software/wget/
15 -- - Lua 5.1.x : http://www.lua.org/
16 -- - LuaExpat : http://www.keplerproject.org/luaexpat/
19 local lxp = require "lxp"
21 local district = arg[1] or "friedrichshain-kreuzberg"
22 local startdate = arg[2] or os.date("%d.%m.%Y")
23 local enddate = arg[3] or startdate
24 local uid_uri = district .. ".bvv.berlin.piratenpartei.de"
26 ----- --- --- -- - - - - -
28 local state = "waitcontent"
29 local record, cell, result = { }, { }, { }
31 local parser = lxp.new {
32 StartElement = function(parser, tagname, attr)
33 if state == "waitcontent" then
34 if tagname == "div" and attr.id == "allrisContent" then
37 elseif state == "waittab" then
38 if tagname == "table" and attr.class == "tl1" then
41 elseif state == "waitrow" then
42 if tagname == "tr" then
47 EndElement = function(parser, tagname)
48 if state == "waitrow" or state == "waittable" then
49 if tagname == "table" then
52 elseif state == "waitcell" then
53 if tagname == "tr" then
54 local day = table.remove(record, 1)
55 local sdate = table.remove(record, 1)
56 local d, m, y = (sdate or ""):match("^%s*(%d+)%.(%d+)%.(%d+)")
57 local time = table.remove(record, 1)
58 if d and m and y and time then
59 local sH, sM, eH, eM = time:match("^%s*(%d+):(%d+)%s*%-%s*(%d+):(%d+)")
61 sH, sM = time:match("^%s*(%d+):(%d+)")
64 local what = table.concat(record, " "):match("^%s*(.-)%s*$")
65 table.insert(result, { y .. m .. d, sH .. sM, eH and eH .. eM, what })
70 elseif tagname == "td" then
71 table.insert(record, table.concat(cell))
76 CharacterData = function(parser, s)
77 if state == "waitcell" then
83 parser:setencoding("ISO-8859-1")
85 ----- --- --- -- - - - - -
87 local cmd = ("wget --quiet --post-data 'kaldatvon=%s&kaldatbis=%s' 'http://www.berlin.de/ba-%s/bvv-online/si010.asp' -O - | tidy -latin1 -asxml -i -w 0 2>/dev/null -q"):format(startdate, enddate, district)
89 local f = io.popen(cmd)
90 for line in f:lines() do
91 -- print(lnr .. " : " .. line)
96 ----- --- --- -- - - - - -
98 print "BEGIN:VCALENDAR"
99 print "PRODID:BVV2CAL"
102 for i = 1, #result do
105 local start = r[1] .. "T" .. r[2]
106 print("UID:" .. start .. "." .. uid_uri)
107 print("SUMMARY:" .. r[4])
108 print("DTSTART:" .. start .. "00Z")
110 print("DTEND:" .. r[1] .. "T" .. r[3] .. "00Z")
115 print "END:VCALENDAR"