# Buggy code
def tzhandler(default, toconf):
    print(
        "\nPlease choose the correct time zone for your blog. Nikola uses the tz database."
    )
    print("You can find your time zone here:")
    print("http://en.wikipedia.org/wiki/List_of_tz_database_time_zones")
    print("")
    answered = False
    while not answered:
        try:
            lz = get_localzone()
        except:
            lz = None
        answer = ask("Time zone", lz if lz else "UTC")
        tz = dateutil.tz.gettz(answer)

        if tz is None:
            print(
                "    WARNING: Time zone not found.  Searching most common timezones for a match."
            )
            zonesfile = tarfile.TarFile.open(
                os.path.join(dateutil.zoneinfo.ZONEINFOFILE)
            )
            zonenames = [
                zone for zone in zonesfile.getnames() if answer.lower() in zone.lower()
            ]
            if len(zonenames) == 1:
                tz = dateutil.tz.gettz(zonenames[0])
            elif len(zonenames) > 1:
                print("    Could not pick one timezone. Choose one of the following:")
                print("        " + "\n        ".join(zonenames))
                continue

        if tz is not None:
            time = datetime.datetime.now(tz).strftime("%H:%M:%S")
            print("    Current time in {0}: {1}".format(answer, time))
            answered = ask_yesno("Use this time zone?", True)
        else:
            print(
                "    ERROR: Time zone not found.  Please try again.  Time zones are case-sensitive."
            )

    SAMPLE_CONF["TIMEZONE"] = answer


# Traceback (AttributeError)
Time zone [Argentina/Buenos_Aires]:
WARNING: Time zone not found.  Searching most common timezones for a match.
Traceback (most recent call last):
File "/mnt/Unsafe/javier/tmp/virtualenvs/blog/lib/python3.4/site-packages/doit/doit_cmd.py", line 121, in run
return command.parse_execute(args)
File "/mnt/Unsafe/javier/tmp/virtualenvs/blog/lib/python3.4/site-packages/doit/cmd_base.py", line 79, in parse_execute
return self.execute(params, args)
File "/mnt/Unsafe/javier/tmp/virtualenvs/blog/lib/python3.4/site-packages/nikola/plugin_categories.py", line 105, in execute
self._execute(options, args)
File "/mnt/Unsafe/javier/tmp/virtualenvs/blog/lib/python3.4/site-packages/nikola/plugins/command/init.py", line 420, in _execute
st = self.ask_questions(target=target)
File "/mnt/Unsafe/javier/tmp/virtualenvs/blog/lib/python3.4/site-packages/nikola/plugins/command/init.py", line 397, in ask_questions
query(default, toconf)
File "/mnt/Unsafe/javier/tmp/virtualenvs/blog/lib/python3.4/site-packages/nikola/plugins/command/init.py", line 323, in tzhandler
zonesfile = tarfile.TarFile.open(os.path.join(dateutil.zoneinfo.ZONEINFOFILE))
AttributeError: 'module' object has no attribute 'ZONEINFOFILE'

# Fixed code
def tzhandler(default, toconf):
    print(
        "\nPlease choose the correct time zone for your blog. Nikola uses the tz database."
    )
    print("You can find your time zone here:")
    print("http://en.wikipedia.org/wiki/List_of_tz_database_time_zones")
    print("")
    answered = False
    while not answered:
        try:
            lz = get_localzone()
        except:
            lz = None
        answer = ask("Time zone", lz if lz else "UTC")
        tz = dateutil.tz.gettz(answer)

        if tz is None:
            print(
                "    WARNING: Time zone not found.  Searching list of time zones for a match."
            )
            zonesfile = tarfile.open(fileobj=dateutil.zoneinfo.getzoneinfofile_stream())
            zonenames = [
                zone for zone in zonesfile.getnames() if answer.lower() in zone.lower()
            ]
            if len(zonenames) == 1:
                tz = dateutil.tz.gettz(zonenames[0])
                answer = zonenames[0]
                print("    Picking '{0}'.".format(answer))
            elif len(zonenames) > 1:
                print("    The following time zones match your query:")
                print("        " + "\n        ".join(zonenames))
                continue

        if tz is not None:
            time = datetime.datetime.now(tz).strftime("%H:%M:%S")
            print("    Current time in {0}: {1}".format(answer, time))
            answered = ask_yesno("Use this time zone?", True)
        else:
            print("    ERROR: No matches found.  Please try again.")

    SAMPLE_CONF["TIMEZONE"] = answer