Example #1
0
def publish_current_observation(data, ch):
    co = data['current_observation']
    
    current_obs = {
        'timestamp'     : time_util.dt_from_epoch_with_tz(int(co['local_epoch']), co['local_tz_long']),
        'station_id'    : co['station_id'],
        'temp_C'        : co['temp_c'],
        'windchill_C'   : _float(co['windchill_c']),
        'dewpoint_C'    : co['dewpoint_c'],
        'rel_humid'     : _float(co['relative_humidity'].replace("%", "")),
        'windspeed_mph' : co['wind_mph'],
        'windgust_mph'  : co['wind_gust_mph'],
        'wind_dir'      : co['wind_degrees'],
        'pressure_mb'   : _float(co['pressure_mb']),
        'visibility_mi' : _float(co['visibility_mi']),
        'weather'       : co['weather'],
        'precip_mm'     : {
            '1hr'   : _float(co['precip_1hr_metric']),
            'today' : _float(co['precip_today_metric']),
        },
    }
    
    # publish to wx.current_observation
    ch.basic_publish(
        exchange='weather',
        routing_key='current_observation',
        properties = pika.BasicProperties(
            content_type = 'application/json'
        ),
        body = serializer_utils.serialize(current_obs, 'application/json')
    )
Example #2
0
def publish_7day_forecast(data, ch):
    daily_forecast = []
    for df in data['forecast']['simpleforecast']['forecastday']:
        daily_forecast.append({
            'timestamp'     : time_util.dt_from_epoch_with_tz(
                int(df['date']['epoch']),
                df['date']['tz_long']
            ),
            'condition'     : (df['conditions'],),
            'hi_temp_C'     : _float(df['high']['celsius']),
            'lo_temp_C'     : _float(df['low']['celsius']),
            'rel_humid'     : _float(df['avehumidity']),
            'avg_windspeed_mph' : _float(df['avewind']['mph']),
            'avg_wind_dir'      : _float(df['avewind']['degrees']),
            'max_windspeed_mph' : _float(df['maxwind']['mph']),
            'max_wind_dir'      : _float(df['maxwind']['degrees']),
            'pct_of_precip' : _float(df['pop']),
        })
    
    # publish to wx.7day_forecast
    ch.basic_publish(
        exchange='weather',
        routing_key='7day_forecast',
        properties = pika.BasicProperties(
            content_type = 'application/json'
        ),
        body=json.dumps(daily_forecast)
    )