5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 import cgitb; cgitb.enable()
30 def exitQuiet(exitstate=0):
31 print('Content-Type: text/html\n')
34 if __name__ == '__main__':
35 form = cgi.FieldStorage()
36 if "uid" not in form or "key" not in form:
37 print('Content-Type: text/html\n')
40 # UID should be numeric, if it's not we have someone playing games
41 uid = int(form['uid'].value)
45 # The user's key will be a 16 character string
46 key = form['key'].value
47 re.search('[&?]+', key) and exitQuiet()
48 len(key) == 16 or exitQuiet()
50 # Historically facebook has been notoriously bad at setting timzeones
51 # in their stuff so this should be a user setting. If it is set in
52 # their calendar it'll be used otherwise if the user feeds crap or
53 # nothing just assume they want Australia/Perth
56 from pytz import timezone
58 timezone(form['tz'].value)
63 ruleConfig["defaultTZ"] = tz or "Australia/Perth"
65 # Okay, we're happy that the input is sane, lets serve up some data
66 url = 'http://www.facebook.com/ical/u.php?uid=%d&key=%s'%(uid,key)
67 (content, encoding) = icalparse.getHTTPContent(url)
69 cal = vobject.readOne(unicode(content, encoding))
70 cal = icalparse.applyRules(cal, icalparse.generateRules(ruleConfig), False)
72 print('Content-Type: text/html; charset=%s\n'%encoding)
73 icalparse.writeOutput(cal)