Exemplo n.º 1
0
 def __init__(self, data_server, twitter_client):
     """
     :param data_server: Current influxdb server
     :param twitter_client: Twitter interface to do da magic
     :return:
     """
     self.server = data_server
     self.twitter = twitter_client
     self.log = master_log.name(__name__)
     self.log.debug("CurrentCondition class created")
Exemplo n.º 2
0
 def __init__(self,data_server):
     self.log = master_log.name(__name__)
     self.server = data_server
     self.data_points = []
     self.current_dataset = {
         'temp': 'temp_c',
         'pressure': 'pressure_mb',
         'humidity': 'relative_humidity',
         'feelslike': 'feelslike_c',
         'wind_direction': 'wind_degrees',
         'wind_gusts'    : 'wind_gust_kph',
         'wind_speed'    : 'wind_kph'
     }
     self.log.debug("Forecast class created")
Exemplo n.º 3
0
    def __init__(self,server = INFLUX_DB_SERVER,
                 port = INFLUX_DB_PORT,
                 table = INFLUX_DB_TABLE,
                 user = INFLUX_DB_USER,
                 passwd = INFLUX_DB_PASSWORD):
        """
        Standard construction. The parameters should be in the environment.
        See utils.config.py
        :param server: Host
        :param port: Port, default to 8086
        :param table: table to be used
        :param user: username
        :param passwd: password
        :return:
        """
        self.log = master_log.name(__name__)

        try:
            self.log.debug("Connecting to" + server)
            self.server = InfluxDBClient(server, port, user, passwd, table)
            self.log.debug("Connected to" + server)
        except Exception as e:
            reason = str(e)
            raise Exception("Unable to connect to {}:{} with {}.{}".format(server, port, user, reason))
Exemplo n.º 4
0
# -*- coding: utf-8 -*-
import sys
## HORRID HACK. REDO.
reload(sys)
sys.setdefaultencoding('utf8')

import datetime
from emoji import emojize
from domus.utils.logger import master_log
log = master_log.name(__name__)
from domus.utils.cache import RedisCache


RAIN_THRESHOLD = {
    u'no llueve': (0, 40),
    emojize(u'llueve :umbrella:'): (75, 100),
    u'puede llover': (40, 74)
    }
#See
#http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1
CONDITION_TO_EMOJI ={
    u'chanceflurries': u':snowflake:',
    u'chancerain': u':umbrella:',
    u'chancesleet': u':snowflake:',
    u'chancesnow':u':snowflake:',
    u'chancetstorms':u':zap:',
    u'clear':u':sunny:',
    u'cloudy':u':cloudy:',
    u'flurries':u':snowflake:',
    u'fog':u':foggy:',
    u'hazy':u':foggy:',
Exemplo n.º 5
0
from redis import StrictRedis, ConnectionError
from domus.utils.logger import master_log
log = master_log.name("DOMUS " + __name__)


class RedisCache(object):

    def __init__(self, params={}):
        self._validate(params)

        if not self.server:
            raise Exception('Redis Server Not Defined')

        try:
            log.debug('Connecting to redis at [%s]?[%s]' % (self.server, self.database))
            self.cache = StrictRedis(self.server, port=self.port, db=self.database)
        except ConnectionError as ex:
            raise Exception("Unable to connect to Redis", ex)

    def get(self, key):
        """
        Fetch a given key from the cache. If the key does not exist, return
        default, which itself defaults to None.
        """
        ckey = self._create_key(key)
        log.debug("Getting the cache key [%s]" % ckey)
        return self.cache.get(ckey)

    def ping(self):
        """
        This command is often used to test if the cache is still alive, or to measure latency.
Exemplo n.º 6
0
 def __init__(self, data_server):
     self.log = master_log.name(__name__)
     self.server = data_server
     self.data_points = []
     self.log.debug("Openweathermap class created")