コード例 #1
0
def load_dyn_properties():
    global dyn_properties
    logger.info('Loading location & weather properties')
    location = get_location()
    if location:
        dyn_properties.update(location)
        city = location.get('city')
        neighborhood = location.get('neighborhood')
        base_location = ''
        if city:
            base_location = city
        elif 'country_name' in location:
            base_location = location.get('country_name')
        elif 'country' in location:
            base_location = location.get('country')
        if base_location:
            if neighborhood:
                location_str = '%s, %s' % (neighborhood, base_location)
            else:
                location_str = base_location
            dyn_properties['location'] = location_str

    weather_prop = None
    if location:
        weather = get_weather('{city}'.format(city=location['city']))
        weather_prop = parse_weather(weather)
    if weather_prop:
        dyn_properties.update(weather_prop)
    if dyn_properties:
        logger.info("Dynamic properties {}".format(dyn_properties))
    else:
        logger.warn("No dynamic properties")
コード例 #2
0
ファイル: loader.py プロジェクト: c4pt000/Sophia-bot
def load_dyn_properties():
    global dyn_properties
    location = get_location()
    if location:
        if 'city' in location:
            dyn_properties['location'] = location.get('city')
        elif 'country_name' in location:
            dyn_properties['location'] = location.get('country_name')

    weather_prop = None
    if location:
        weather = get_weather('{city},{country}'.format(
            city=location['city'], country=location['country_code']))
        weather_prop = parse_weather(weather)
    if weather_prop:
        dyn_properties.update(weather_prop)
    logger.info("Update dynamic properties {}".format(dyn_properties))
コード例 #3
0
def render_weather(t):
    if hasattr(t.module, 'location'):
        location = t.module.location
    else:
        location = get_location()
        if location:
            if 'city' in location:
                location = location.get('city')
    city = query_city_info(location)
    if 'id' in city:
        id = city['id']
        weather = get_weather_by_id(id)
        weather_prop = parse_weather(weather)
        desc = weather_prop['weather']
        temperature = '{} degrees'.format(weather_prop['temperature'])
        return t.render(weatherdesc=desc,
                        temperature=temperature,
                        location=city)
コード例 #4
0
ファイル: loader.py プロジェクト: wenwei-dev/HEAD
def load_dyn_properties():
    global dyn_properties
    location = get_location()
    if location:
        if 'city' in location:
            dyn_properties['location'] = location.get('city')
        elif 'country_name' in location:
            dyn_properties['location'] = location.get('country_name')

    weather_prop = None
    if location:
        weather = get_weather(
            '{city},{country}'.format(
                city=location['city'], country=location['country_code']))
        weather_prop = parse_weather(weather)
    if weather_prop:
        dyn_properties.update(weather_prop)
    logger.info("Update dynamic properties {}".format(dyn_properties))
コード例 #5
0
def render_location(t):
    location = get_location()
    if location:
        if 'city' in location:
            location = location.get('city')
            return t.render(location=location)