text: #!/usr/bin/env python
  import sys
  
  import pytz
  import datetime
  
  BASE_DATE = datetime.datetime(year=2009,month=1,day=1,
                                tzinfo=pytz.timezone('UTC'))
  
  def main():
      cols = sys.stdin.readline().rstrip('\n').split('\t')
      offset_rows = []
      name_rows = []
      print '%% @copyright 2010 Mochi Media, Inc.'
      print '%% @doc Autogenerated mapping of countries (and region) to'
      print '%%      standard time UTC offsets.'
      print '%%      Generated by ../support/make_tz.py'
      print '-module(egeoip_tz).'
      print '-export([utc_offset/1, name/1]).'
      print '-record(geoip, {country_code, country_code3, country_name, region,'
      print '    city, postal_code, latitude, longitude, area_code, dma_code}).'
      
      for line in sys.stdin:
          row = dict(zip(cols, line.rstrip('\n').split('\t')))
          try:
              tz = pytz.timezone(row['timezone'])
          except pytz.UnknownTimeZoneError:
              continue
          d = BASE_DATE.astimezone(tz)
          utcoffset = d.tzinfo.utcoffset(d)
          usecs = (utcoffset.days * 86400) + utcoffset.seconds
          if row['region']:
              offset_rows.append(
                  'utc_offset(#geoip{country_code = "%s", region = <<"%s">>}) -> %s' %
                  (row['country'], row['region'], usecs))
              name_rows.append(
                  'name(#geoip{country_code = "%s", region = <<"%s">>}) -> "%s"' %
                  (row['country'], row['region'], row['timezone']))
          else:
              offset_rows.append(
                  'utc_offset(#geoip{country_code = "%s"}) -> %s' % (row['country'], usecs))
              name_rows.append(
                  'name(#geoip{country_code = "%s"}) -> "%s"' % (row['country'], row['timezone']))
      offset_rows.append('utc_offset(_) -> 0')
      name_rows.append('name(_) -> undefined')
      print ';\n'.join(offset_rows) + '.'
      print ';\n'.join(name_rows) + '.'
  
  if __name__ == '__main__':
      main()
  