Ein Ersatz für:
Code: Alles auswählen
TZ_CHOICES = [(float(x[0]), x[1]) for x in (
(-12, '-12'), (-11, '-11'), (-10, '-10'), (-9.5, '-09.5'), (-9, '-09'),
(-8.5, '-08.5'), (-8, '-08 PST'), (-7, '-07 MST'), (-6, '-06 CST'),
(-5, '-05 EST'), (-4, '-04 AST'), (-3.5, '-03.5'), (-3, '-03 ADT'),
(-2, '-02'), (-1, '-01'), (0, '00 GMT'), (1, '+01 CET'), (2, '+02'),
(3, '+03'), (3.5, '+03.5'), (4, '+04'), (4.5, '+04.5'), (5, '+05'),
(5.5, '+05.5'), (6, '+06'), (6.5, '+06.5'), (7, '+07'), (8, '+08'),
(9, '+09'), (9.5, '+09.5'), (10, '+10'), (10.5, '+10.5'), (11, '+11'),
(11.5, '+11.5'), (12, '+12'), (13, '+13'), (14, '+14'),
)]
Hab mal im Internet gesucht. Aber meist findet man nur listen mit zu vielen Städten. Die besten Treffer sind noch:
http://msdn.microsoft.com/en-us/library ... 11%29.aspx
http://www.davidsemporium.co.uk/worldclock.html
Ich dachte vielleicht bekomme ich die info's ja von pytz und hab ein Skript gebastelt:
Code: Alles auswählen
import collections
from datetime import datetime
import pytz
def get_shortest(l, max=3):
"""
>>> get_shortest(["aa","bbb","c","dd"])
['c', 'aa', 'dd']
>>> get_shortest(["aa","b","cc","d"], 2)
['b', 'd']
"""
l = sorted(l, key=lambda x: len(x))
return l[:max]
def get_human_timezones(max_cities=3, max_countries=4):
human_timezones = {}
utc = pytz.timezone('UTC')
utc_now = datetime.now()#.replace(tzinfo=utc)
timezone_data = {}#collections.defaultdict(list)
for zone_name in pytz.common_timezones:
tz = pytz.timezone(zone_name)
dt = tz.localize(utc_now)
offset = dt.strftime("%z")
#~ utcoffset = tz._utcoffset # timedelta object
#~ offset = utcoffset.total_seconds() / 60
if offset not in timezone_data:
timezone_data[offset] = [dt.strftime("%Z")]
timezone_data[offset].append(zone_name)
for utc_offset, data in timezone_data.items():
tz_acronym = data[0]
places = data[1:]
places_dict = collections.defaultdict(list)
for place in places:
if "/" in place:
country, cities = place.split("/",1)
places_dict[country].append(cities)
human_places = []
for country, cities in sorted(places_dict.items()):
cities = get_shortest(cities, max=max_cities)
human_places.append(
"%s:%s" % (country, ",".join(cities))
)
human_places = "%s - %s" % (
tz_acronym, " - ".join(human_places)
)
human_timezones[utc_offset] = human_places
return human_timezones
if __name__ == "__main__":
human_timezones = get_human_timezones(max_cities=3, max_countries=4)
for utc_offset, human_places in sorted(human_timezones.items(), key=lambda x: int(x[0])):
print utc_offset, human_places
Dumm ist halt, das auch hier zu viele Städte dabei sind und ich deswegen schon das ganze mit get_shortest() kürze...-1100 SST - Pacific:Niue,Midway,Pago_Pago
-1000 HST - Pacific:Tahiti,Honolulu,Johnston - US:Hawaii
-0930 MART - Pacific:Marquesas
-0900 HADT - America:Adak - Pacific:Gambier
-0800 AKDT - America:Nome,Sitka,Juneau - Pacific:Pitcairn - US:Alaska
-0700 PDT - America:Dawson,Phoenix,Tijuana - Canada:Pacific - US:Arizona,Pacific
-0600 CST - America:Boise,Belize,Denver - Canada:Mountain - Pacific:Easter,Galapagos - US:Mountain
-0500 EST - America:Lima,Bogota,Cancun - Canada:Central - US:Central
-0430 VET - America:Caracas
-0400 AST - America:Aruba,Cuiaba,Guyana - Antarctica:Palmer - Canada:Eastern - US:Eastern
-0300 BRT - America:Bahia,Belem,Thule - Antarctica:Rothera - Atlantic:Bermuda,Stanley - Canada:Atlantic
-0230 NDT - America:St_Johns - Canada:Newfoundland
-0200 WGST - America:Godthab,Noronha,Miquelon - Atlantic:South_Georgia
-0100 CVT - Atlantic:Cape_Verde
+0000 GMT - Africa:Lome,Accra,Dakar - America:Danmarkshavn,Scoresbysund - Atlantic:Azores,Reykjavik,St_Helena
+0100 CET - Africa:Lagos,Tunis,Bangui - Atlantic:Faroe,Canary,Madeira - Europe:Dublin,Jersey,Lisbon
+0200 CAT - Africa:Cairo,Ceuta,Harare - Arctic:Longyearbyen - Europe:Oslo,Rome,Malta
+0300 EAT - Africa:Asmara,Kampala,Nairobi - Antarctica:Syowa - Asia:Aden,Gaza,Amman - Europe:Kiev,Riga,Minsk - Indian:Comoro,Mayotte,Antananarivo
+0400 GST - Asia:Dubai,Muscat,Tbilisi - Europe:Moscow,Samara,Volgograd - Indian:Mahe,Reunion,Mauritius
+0430 AFT - Asia:Kabul,Tehran
+0500 MAWT - Antarctica:Mawson - Asia:Baku,Oral,Aqtau - Indian:Maldives,Kerguelen
+0530 IST - Asia:Colombo,Kolkata
+0545 NPT - Asia:Kathmandu
+0600 VOST - Antarctica:Vostok - Asia:Dhaka,Almaty,Bishkek - Indian:Chagos
+0630 MMT - Asia:Rangoon - Indian:Cocos
+0700 DAVT - Antarctica:Davis - Asia:Hovd,Omsk,Bangkok - Indian:Christmas
+0800 WST - Antarctica:Casey - Asia:Macau,Brunei,Harbin - Australia:Perth
+0845 CWST - Australia:Eucla
+0900 TLT - Asia:Dili,Seoul,Tokyo - Pacific:Palau
+0930 CST - Australia:Darwin,Adelaide,Broken_Hill
+1000 DDUT - Antarctica:DumontDUrville - Asia:Yakutsk - Australia:Currie,Hobart,Sydney - Pacific:Guam,Chuuk,Saipan
+1030 LHST - Australia:Lord_Howe
+1100 MIST - Antarctica:Macquarie - Asia:Sakhalin,Vladivostok - Pacific:Efate,Kosrae,Noumea
+1130 NFT - Pacific:Norfolk
+1200 NZST - Antarctica:McMurdo,South_Pole - Asia:Anadyr,Magadan,Kamchatka - Pacific:Fiji,Wake,Nauru
+1245 CHAST - Pacific:Chatham
+1300 WST - Pacific:Apia,Fakaofo,Enderbury
+1400 LINT - Pacific:Kiritimati
Wenn man eine Datenbank mit den Einwohnerzahlen der Städte hätte, dann könnte man das richtig machen...