Beispiel #1
0
def main():
    GW = FriskByGW()
    base_url = 'http://www.luftkvalitet.info/home/overview.aspx?type=2&topic=1&id=%'
    key_bg1 = '7b751808f5-d561-4737-9185-4ecc0e834975%7d'  # LODDEFJORD
    key_bg2 = '7b4ff685c1-ad51-4468-b2fc-08345d11f447%7d'  # DANMARKSPLASS
    key_bg3 = '7b5b0ff070-e6e6-4f60-88a3-bd923ac3a7e6%7d'  # RAADHUSET
    key_bg4 = '7bceade2ac-e62f-4e50-af7c-347e402fff27%7d'  # AASANE

    luft_map = {
        "BG_1": '%s%s' % (base_url, key_bg1),
        "BG_2": '%s%s' % (base_url, key_bg2),
        "BG_3": '%s%s' % (base_url, key_bg3),
        "BG_4": '%s%s' % (base_url, key_bg4)
    }

    bergen_tz = pytz.timezone('Europe/Oslo')
    bergen_time = dt.now(bergen_tz)

    for device in luft_map:
        try:
            url_read = pd.read_html(luft_map[device], header=0,
                                    thousands=".")[1]
            df = url_read.values.tolist()
            post_data(GW, device, df, bergen_time)
        except ValueError as err:
            print('Error occurred on device = %s: %s.' % (device, err))
Beispiel #2
0
    def test_get_sensor(self):
        if network == False:
            sys.stderr.write(
                "Sorry - no network connection - skipping GW tests\n")
            return

        gw = FriskByGW()
        sensor = gw.getSensor("NO/does/not/exist")
        self.assertIsNone(sensor)
Beispiel #3
0
    def test_get_sensors(self):
        if network == False:
            sys.stderr.write(
                "Sorry - no network connection - skipping GW tests\n")
            return

        gw = FriskByGW()
        sensors = gw.sensorList()
        for sensor in sensors:
            self.assertTrue(isinstance(sensor, FriskBySensor))

        if len(sensors) > 0:
            sensor = sensors[0]

        try:
            last_value = sensor.getLastValue()
        except Exception:
            pass
Beispiel #4
0
#!/usr/bin/env python
import sys
import requests
import random
import time
from friskby_gw import FriskByGW


<<<<<<< Updated upstream
gw = FriskByGW( )
key = "00001111-2222-3333-4444-555566667777"
sensor_id = "RANDOM"
sensor = gw.getSensor( sensor_id , key = key )
=======
gw = FriskByGW( url = "http://127.0.0.1:8000/" )
sensor_id = "RANDOM"
sensor_id = "TEST1"
sensor = gw.getSensor(sensor_id)
>>>>>>> Stashed changes
if sensor is None:
    msg = "Sorry - the friskby server at:%s does not have a %s sensor - add that manually first." % (gw.getRootURL() , sensor_id)
    sys.exit( msg )

num = 1
min_value = sensor.getMinValue( )
max_value = sensor.getMaxValue( )
sleep_time = 1
corr = 0.90

if len(sys.argv) > 1:
    num = int(sys.argv[1])
Beispiel #5
0
#!/usr/bin/env python

from datetime import date
import pandas as pd
from friskby_gw import FriskByGW

sensor_types = ['_PM10', '_PM25']

GW = FriskByGW()

luft_map = {
    "BG_1":
    "http://www.luftkvalitet.info/home/"
    "overview.aspx?type=2&topic=1&id=%7b751808f5-d561-4737-9185-4ecc0e834975%7d",  # LODDEFJORD
    "BG_2":
    "http://luftkvalitet.info/"
    "home/overview.aspx?type=2&topic=1&id=%7b4ff685c1-ad51-4468-b2fc-08345d11f447%7d",  # DANMARKSPLASS
    "BG_3":
    "http://www.luftkvalitet.info/home/"
    "overview.aspx?type=2&topic=1&id=%7b5b0ff070-e6e6-4f60-88a3-bd923ac3a7e6%7d",  # RAADHUSET
    "BG_4":
    "http://www.luftkvalitet.info/home/"
    "overview.aspx?type=2&topic=1&id=%7bceade2ac-e62f-4e50-af7c-347e402fff27%7d"  # AASANE
}
# keys for parsing data
komponent_id = ["PM10", "PM2.5"]

key = "9fbb2727-067d-4618-af05-e45cafdd673d"

current_date = date.today().isoformat()
Beispiel #6
0
import xml.etree.ElementTree as ET
import sys
import requests
import random
import datetime
from friskby_gw import FriskByGW

sensor_map = {
    "MET:TEMP:FLORIDA":
    "http://www.yr.no/place/Norway/Hordaland/Bergen/Bergen_(Florida)_observation_site/varsel.xml",
    "MET:TEMP:BLINDERN":
    "http://www.yr.no/place/Norway/Oslo/Oslo/Blindern/varsel.xml"
}

key = "00001111-2222-3333-4444-555566667777"
gw = FriskByGW()
for sensor_id, url in sensor_map.items():
    sensor = gw.getSensor(sensor_id, key=key)
    if sensor is None:
        msg = "Sorry - the friskby server at:%s does not have a %s sensor - add that manually first." % (
            gw.getRootURL(), sensor_id)

    response = requests.get(url)
    if response.status_code == 200:
        source = response.text
        tree = ET.fromstring(source.encode("utf-8"))
        temp_node = tree.find("observations").find("weatherstation").find(
            "temperature")

        temp = float(temp_node.get("value"))
        ts = temp_node.get("time")