imip-agent

Annotated tools/make_freebusy.py

245:b0b6ce5bbe43
2015-02-03 Paul Boddie Added some explanations of the various day-related functions.
paul@120 1
#!/usr/bin/env python
paul@120 2
paul@120 3
from imiptools.content import format_datetime, get_utc_datetime, get_value, parse_object
paul@120 4
from imip_store import FileStore, FilePublisher
paul@120 5
import sys
paul@120 6
paul@120 7
try:
paul@120 8
    user = sys.argv[1]
paul@120 9
except IndexError:
paul@120 10
    print >>sys.stderr, "Need a user."
paul@120 11
    sys.exit(1)
paul@120 12
paul@120 13
s = FileStore()
paul@120 14
p = FilePublisher()
paul@120 15
paul@120 16
l = s.get_events(user)
paul@120 17
paul@120 18
objs = []
paul@120 19
for i in l:
paul@120 20
    print >>sys.stderr, i
paul@120 21
    objs.append(parse_object(s.get_event(user, i), "utf-8"))
paul@120 22
paul@120 23
fb = []
paul@120 24
for obj in objs:
paul@120 25
    if not obj:
paul@120 26
        continue
paul@120 27
    details, details_attr = obj.values()[0]
paul@120 28
    fb.append((format_datetime(get_utc_datetime(details, "DTSTART")),
paul@120 29
               format_datetime(get_utc_datetime(details, "DTEND")),
paul@120 30
               get_value(details, "UID"),
paul@120 31
               get_value(details, "TRANSP")))
paul@120 32
paul@120 33
fb.sort()
paul@120 34
paul@120 35
s.set_freebusy(user, fb)
paul@120 36
p.set_freebusy(user, fb)
paul@120 37
paul@120 38
# vim: tabstop=4 expandtab shiftwidth=4