def get_temp(weather_units, temp):
    try:
        temp = float(temp)
    except (KeyError, TypeError, ValueError):
        return 'unknown'

    # check user preferences, default to both if unset
    if weather_units == "both" or weather_units is None:
        return u'%d\u00B0C (%d\u00B0F)' % (round(temp), round(c_to_f(temp)))
    elif weather_units == "metric":
        return u'%d\u00B0C' % (round(temp))
    elif weather_units == "imperial":
        return u'%d\u00B0F' % (round(c_to_f(temp)))
Beispiel #2
0
def get_tomorrow_low(results):
    temp = None
    # Only using the first 8 results to get the next 24 hours (8 * 3 hours)
    for _ in results['list'][:8]:
        if temp is None or _['main']['temp_min'] < temp:
            temp = _['main']['temp_min']
    return u'Low: %d\u00B0C (%d\u00B0F)' % (temp, c_to_f(temp))
Beispiel #3
0
def get_temp(parsed):
    try:
        condition = parsed['channel']['item']['yweather:condition']
        temp = int(condition['@temp'])
    except (KeyError, ValueError):
        return 'unknown'
    return (u'%d\u00B0C (%d\u00B0F)' % (temp, c_to_f(temp)))
Beispiel #4
0
def get_tomorrow_low(parsed):
    try:
        tomorrow_low = int(
            parsed['channel']['item']['yweather:forecast'][2]['@low'])
    except (KeyError, ValueError):
        return 'unknown'
    return ('Low: %s\u00B0C (%s\u00B0F)' %
            (tomorrow_low, c_to_f(tomorrow_low)))
Beispiel #5
0
def get_tomorrow_high(parsed):
    try:
        tomorrow_high = int(
            parsed['channel']['item']['yweather:forecast'][2]['@high'])
    except (KeyError, ValueError):
        return 'unknown'
    return ('High: %s\u00B0C (%s\u00B0F)' %
            (tomorrow_high, c_to_f(tomorrow_high)))
Beispiel #6
0
def get_temp(parsed):
    try:
        temp = float(parsed['main']['temp'])
    except (KeyError, TypeError, ValueError):
        return 'unknown'
    return u'%d\u00B0C (%d\u00B0F)' % (round(temp), round(c_to_f(temp)))
Beispiel #7
0
def get_temp(temp):
    try:
        temp = float(temp)
    except (KeyError, TypeError, ValueError):
        return 'unknown'
    return u'%d\u00B0C (%d\u00B0F)' % (round(temp), round(c_to_f(temp)))
Beispiel #8
0
def _parse_data(data, timezone):
    """parse data"""

    string = ""
    idx = 0
    for key, values in data.items():
        value_map = values
        if idx == 0:
            prefix = ""
        else:
            prefix = " | "

        if key in ["lat", "lon", "observation_time"]:
            continue
        if not value_map.get('value') or value_map.get('value') == 'none':
            continue

        if key == "weather_code":
            value_map = {'value': WEATHER_CODE_DESCRIPTIONS[values['value']]}

        if value_map.get('units'):
            if value_map['units'] == "F":
                f_color = _get_temp_color(value_map['value'])
                value_map = {
                    'value':
                    "{}°F/{}°C".format(
                        color("{}".format(round(value_map['value'])), f_color),
                        color(
                            "{}".format(round(f_to_c(value_map['value']), 1)),
                            f_color),
                    )
                }
            elif value_map['units'] == "C":
                f_color = _get_temp_color(c_to_f(value_map['value']))
                value_map = {
                    'value':
                    "{}°C/{}°F".format(
                        color("{}".format(round(value_map['value'], 1)),
                              f_color),
                        color("{}".format(round(c_to_f(value_map['value']))),
                              f_color),
                    )
                }

        if key == "wind_direction":
            value_map = {'value': get_wind(values['value'])}

        if key in ["sunrise", "sunset"]:
            value_map = {'value': _parse_time(values['value'], timezone)}

        try:
            value_map['value'] = _get_value_format(value_map['value'], key)
        except:
            pass

        template = Template("{pfx}{field} $value$units").safe_substitute(
            value_map)
        string += template.format(
            pfx=prefix,
            field=MAPPED_FIELDS.get(key, ""),
        )
        idx += 1

    return string.replace('$units', '')