Ejemplo n.º 1
0
def search(query: str):
    """
    Get time based on the entered timezone.
    """
    try:
        # Search with user query.
        # TODO: Handle list with multiple data.
        data: List = pycountry.countries.search_fuzzy(query)

        # extract alpha2 value
        _, _, alpha_2, _ = utils.extract_fuzzy_country_data(data)

        # Get a list of timezone names.
        result = utils.get_timezones(alpha_2)

        payload: List = []

        # If length is greater than one, show terminal menu.
        if len(result) > 1:
            entry = utils.handle_interaction(result)

            payload.append(entry)

            return utils.get_local_time(payload)
    except LookupError:
        return console.print(
            "Couldn't resolve your query, please try other keywords.:x:")

    return utils.get_local_time(result)
Ejemplo n.º 2
0
def select():
    """
    Interactively select the timezone from your config file to get local time.
    """
    config_file = variables.config_file
    entry = []

    with open(config_file, "r+") as file:
        data = [line.rstrip() for line in file]

        if not len(data):
            return console.print("Config file contains no timezone:x:")

        entry.append(utils.handle_interaction(data))

        return utils.get_local_time(entry)
Ejemplo n.º 3
0
def show():
    """
    Show time based on the defaults at .tz-cli file.
    """
    check_config: Union[List, bool] = utils.check_config()

    if not check_config:
        console.print(
            "File is empty or No configuration file is present in your system.:x:\n",
            style="bold red",
        )
        console.print(
            "Use `tz add` to create and add timezone to your config file.:memo:\n",
            style="bold green",
        )

        console.print(
            f"Your system datetime is: {utils.get_system_time()}",
            style="bold yellow",
        )
        sys.exit()

    return utils.get_local_time(check_config)