comparison tools/tz.py @ 245:ed6202fb08b6

Update timezone.js based on pytz 2010b data. Control the tz.py script that generates this data. Ticket #96.
author Brian Neal <bgneal@gmail.com>
date Sat, 18 Sep 2010 18:56:22 +0000
parents
children
comparison
equal deleted inserted replaced
244:a61b1c598001 245:ed6202fb08b6
1 """
2 This program generates the data used by the timezone.js Javascript.
3 This data is used to create the 2 dropdown select boxes for timezones.
4 """
5 import pytz
6 from pprint import pprint
7
8 def format_locations(locs):
9 ss = ["[%s]" % ", ".join(["'%s'" % l for l in loc]) for loc in locs]
10 return "%s" % ",\n".join(ss)
11
12 # get a list of areas
13
14 zones = [z.split('/') for z in pytz.common_timezones]
15 areas = set([zone[0] for zone in zones if len(zone) > 1])
16 areas = list(areas)
17 areas.sort()
18
19 locations = dict([(area, []) for area in areas])
20
21 #pprint(locations)
22
23 for zone in pytz.common_timezones:
24 if zone.count('/') == 0:
25 continue
26 area, loc = zone.split('/', 1)
27 if area in locations:
28 locations[area].append(loc.replace('_', ' '))
29
30 #pprint(locations)
31
32 for area in locations.iterkeys():
33 locations[area].sort()
34
35 locs = []
36 for area in areas:
37 locs.append(locations[area])
38
39 #pprint(locs)
40
41 default_area = areas.index('US')
42 default_location = locs[default_area].index('Pacific')
43
44 print """\
45 var gcalTzInfo = {
46 areas: [%s],
47 locations: [%s],
48 default_area: %s,
49 default_location: %s
50 };
51 """ % (", ".join(["'%s'" % area for area in areas]),
52 format_locations(locs),
53 default_area,
54 default_location,
55 )