# Generates fourTwentyTz.js from time zone csv files # get latest files from https://timezonedb.com/download import csv,json,time,os,math countries = {} for r in csv.reader(open("country.csv")): countries[r[0]] = r[1] zones = {} for r in csv.reader(open("zone.csv")): parts = r[2].replace('_',' ').split('/') city = parts[-1] if len(parts)>2: # e.g. America/North_Dakota/New_Salem country = parts[1] # e.g. North Dakota else: # e.g. America/Denver country = countries[r[1]] # e.g. United States if country==city: # Avoid awkward searches like "Anguilla, Anguilla" country = r[1] # Use code instead zones[int(r[0])] = {"name":', '.join((city,country))} now = int(time.time()) for r in csv.reader(open("timezone.csv")): code = int(r[0]) if code not in zones: continue starttime = int(r[2] or "0") # Bugger. They're feeding us blanks for UTC now offs = int(r[3]) if offs < 0: offs += 60*60*24 d = zones[code] if starttime