bgneal@245: """ bgneal@245: This program generates the data used by the timezone.js Javascript. bgneal@245: This data is used to create the 2 dropdown select boxes for timezones. bgneal@245: """ bgneal@245: import pytz bgneal@245: from pprint import pprint bgneal@245: bgneal@245: def format_locations(locs): bgneal@245: ss = ["[%s]" % ", ".join(["'%s'" % l for l in loc]) for loc in locs] bgneal@245: return "%s" % ",\n".join(ss) bgneal@245: bgneal@245: # get a list of areas bgneal@245: bgneal@245: zones = [z.split('/') for z in pytz.common_timezones] bgneal@245: areas = set([zone[0] for zone in zones if len(zone) > 1]) bgneal@245: areas = list(areas) bgneal@245: areas.sort() bgneal@245: bgneal@245: locations = dict([(area, []) for area in areas]) bgneal@245: bgneal@245: #pprint(locations) bgneal@245: bgneal@245: for zone in pytz.common_timezones: bgneal@245: if zone.count('/') == 0: bgneal@245: continue bgneal@245: area, loc = zone.split('/', 1) bgneal@245: if area in locations: bgneal@245: locations[area].append(loc.replace('_', ' ')) bgneal@245: bgneal@245: #pprint(locations) bgneal@245: bgneal@245: for area in locations.iterkeys(): bgneal@245: locations[area].sort() bgneal@245: bgneal@245: locs = [] bgneal@245: for area in areas: bgneal@245: locs.append(locations[area]) bgneal@245: bgneal@245: #pprint(locs) bgneal@245: bgneal@245: default_area = areas.index('US') bgneal@245: default_location = locs[default_area].index('Pacific') bgneal@245: bgneal@245: print """\ bgneal@245: var gcalTzInfo = { bgneal@245: areas: [%s], bgneal@245: locations: [%s], bgneal@245: default_area: %s, bgneal@245: default_location: %s bgneal@245: }; bgneal@245: """ % (", ".join(["'%s'" % area for area in areas]), bgneal@245: format_locations(locs), bgneal@245: default_area, bgneal@245: default_location, bgneal@245: )