Beispiel #1
0
    # Get sqft, beds, baths
    desc = apt.find_element_by_xpath(
        './/div[contains(@class, "apartment__unit-description")]').text.split(
            '\n')
    for d in desc:
        for item in ['bed', 'bath', 'sq. ft.']:
            if item in d.lower():
                apt_dict[re.sub(r'\W+', '',
                                item)] = int(re.search(r'\d+', d).group())
                break
    # Get price
    price = apt.find_element_by_xpath(
        './/div[contains(@class, "apartment__price")]'
        '/div[contains(@class, "apartment__description")]').text
    price = int(''.join(re.findall(r'\d+', price)))
    apt_dict.update({'price': price, 'unit': unit})
    apt_list.append(apt_dict)

ba.tear_down()
logg.debug(f'Processed {len(apt_list)} listings...')

if len(apt_list) > 0:
    # Add to influx
    apt_df = pd.DataFrame(apt_list)
    logg.debug(f'Writing {apt_df.shape[0]} rows to influx...')
    influx.write_df_to_table(apt_df,
                             tags='unit',
                             value_cols=['bed', 'bath', 'sqft', 'price'])

logg.close()
Beispiel #2
0
log = LogWithInflux('ha-temps', log_dir='weather')
influx = InfluxDBLocal(InfluxDBHomeAuto.TEMPS)

query = '''
    SELECT 
        last("temp") AS temp,
        last("humidity") AS humidity
    FROM "temps"
    WHERE 
        location =~ /mushroom|r6du|elutuba|wc|v2lis|freezer|fridge|kontor/
        AND time > now() - 30m
    GROUP BY 
        "location" 
    fill(null)
    ORDER BY ASC
'''
df = influx.read_query(query, time_col='time')
log.debug(f'Collected {df.shape[0]} rows of data')

log.debug('Beginning to send updates to HASS')
ha = HAHelper()
for i, row in df.iterrows():
    loc_name = row['location'].replace('-', '_')
    for sensor_type in ['temp', 'humidity']:
        dev_name = f'sensor.{loc_name}_{sensor_type}'
        log.debug(f'Updating {dev_name}...')
        ha.set_state(dev_name, data={'state': row[sensor_type]}, data_class=sensor_type)
log.debug('Update completed.')

log.close()