#!/usr/bin/env python3
''' common functions and stuff '''
import os
import sys
QUEUE = bool(os.environ.get('el_QUEUE', False))
name = os.path.splitext(os.path.split(sys.argv[0])[-1])[0]
sql = {
'elvia': """
INSERT INTO
elvia
VALUES(%s, %s, %s, %s, %s, %s)
ON CONFLICT (startTime,endTime) DO NOTHING""",
'elvia_gridtariff': """
INSERT INTO
elvia_gridtariff
VALUES(%s, %s, %s, %s, %s, %s, %s)
ON CONFLICT (meteringPointId,startTime,endTime) DO NOTHING""",
'entsoe': """
INSERT INTO
entsoe
VALUES(%s, %s, %s)
ON CONFLICT (starttime, zone) DO NOTHING""",
'nb': """
INSERT INTO
nbex
VALUES(%s, %s, %s, %s)
ON CONFLICT (startdate,base_cur,quote_cur) DO NOTHING""",
'neohub': """
INSERT INTO
neohub
(timestamp,
time,
device_id,
away,
heat_mode,
heat_on,
current_floor_temperature,
target_temperature,
temperature)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)""",
'tibber_consumption': """
INSERT INTO
tibber_consumption
VALUES(%s, %s, %s, %s, %s, %s, %s)
ON CONFLICT (startTime,endTime) DO NOTHING""",
'tibber_prices': """
INSERT INTO
tibber_prices
VALUES(%s, %s, %s, %s, %s)
ON CONFLICT (startsat) DO NOTHING""",
'yr': """
INSERT INTO
yr
VALUES(%s, %s, %s, %s, %s, %s, %s)
ON CONFLICT (time) DO UPDATE SET
air_temperature=EXCLUDED.air_temperature,
air_pressure_at_sea_level=EXCLUDED.air_pressure_at_sea_level,
cloud_area_fraction=EXCLUDED.cloud_area_fraction,
relative_humidity=EXCLUDED.relative_humidity,
wind_from_direction=EXCLUDED.wind_from_direction,
wind_speed=EXCLUDED.wind_speed,
updated=now()""",
}
# Initialize queue
if QUEUE is True:
from .queue import dbi
else:
from .postgres import dbi