import pytz


def get_tz(tz):
    """
    Pass a string and return  a pytz timezone object.
    This function can also infer the timezone from the city, if it is a substring of the timezone. e.g. 'Dubai' will return 'Asia/Dubai.'
    """
    try:
        t_z = pytz.timezone(tz)

    except pytz.UnknownTimeZoneError:
        print("Searching for TZ...")
        zones = pytz.common_timezones
        for z in list(zones):
            if (tz in z) and (tz not in list(zones)):
                tz = z
                print(f"Timezone: {z}")
        t_z = pytz.timezone(tz)

    return t_z