Esempio n. 1
0
    if user is None:
        return -1
    elif user.end_night_rate > user.start_night_rate:
        if now > user.start_night_rate and now < user.end_night_rate:
            return 1
        else:
            return 0
    else:
        if now > user.start_night_rate or now < user.end_night_rate:
            return 1
        else:
            return 0


# Configuration
config = Config()

# DB initialization
database_url = (config.get("database_type") + "://" + config.get("username") +
                ":" + config.get("password") + "@" + config.get("host") + "/" +
                config.get("database"))
engine = create_engine(database_url, echo=config.get("debug"))
create_session = sessionmaker(bind=engine)
database.Base.metadata.create_all(engine)

try:
    while True:
        power = random.randint(0, 4000)
        power = math.sin(time.clock() * 2)**2 * 2000
        print("New encrypted packet:" + str(power))
Esempio n. 2
0
    login = post.get("login")
    user = db.query(database.User).filter_by(login=login).first()

    password = (
        config.get("salt") +
        hashlib.sha256(post.get("password", "").encode('utf-8')).hexdigest())
    if user and user.password == password:
        return True
    else:
        return False


# ===============
# Initializations
# ===============
config = Config()
database_url = (config.get("database_type") + "://" + config.get("username") +
                ":" + config.get("password") + "@" + config.get("host") + "/" +
                config.get("database"))
engine = create_engine(database_url, echo=config.get("debug"))

app = Bottle()
plugin = sqlalchemy.Plugin(engine,
                           database.Base.metadata,
                           keyword='db',
                           create=True,
                           commit=True,
                           use_kwargs=False)
app.install(plugin)

session_manager = PickleSession()
Esempio n. 3
0
    login = post.get("login")
    user = db.query(database.User).filter_by(login=login).first()

    password = (config.get("salt") +
                hashlib.sha256(post.get("password", "").encode('utf-8'))
                .hexdigest())
    if user and user.password == password:
        return True
    else:
        return False


# ===============
# Initializations
# ===============
config = Config()
database_url = (config.get("database_type") + "://" + config.get("username") +
                ":" + config.get("password") + "@" + config.get("host") + "/" +
                config.get("database"))
engine = create_engine(database_url, echo=config.get("debug"))

app = Bottle()
plugin = sqlalchemy.Plugin(
    engine,
    database.Base.metadata,
    keyword='db',
    create=True,
    commit=True,
    use_kwargs=False
)
app.install(plugin)
            return 1
        else:
            return 0

def get_cw_sensor():
    """Returns the citizenwatt sensor object or None"""
    db = create_session()
    sensor = (db.query(database.Sensor)
              .filter_by(name="CitizenWatt")
              .first())
    db.close()
    return sensor


# Configuration
config = Config()

# DB initialization
database_url = (config.get("database_type") + "://" + config.get("username") +
                ":" + config.get("password") + "@" + config.get("host") + "/" +
                config.get("database"))
engine = create_engine(database_url, echo=config.get("debug"))
create_session = sessionmaker(bind=engine)
database.Base.metadata.create_all(engine)

sensor = get_cw_sensor()
while not sensor or not sensor.aes_key:
    tools.warning("Install is not complete ! " +
                    "Visit http://citizenwatt.local first.")
    time.sleep(1)
    sensor = get_cw_sensor()
Esempio n. 5
0
#!/usr/bin/env python3

import bisect
import datetime
import json
import numpy
import redis

from libcitizenwatt import database
from libcitizenwatt import tools
from sqlalchemy import asc, desc
from libcitizenwatt.config import Config

config = Config()


def do_cache_ids(sensor, watt_euros, id1, id2, db, force_refresh=False):
    """
    Computes the cache (if needed) for the API call
    /api/<sensor:int>/get/<watt_euros:re:watts|kwatthours|euros>/by_id/<id1:int>/<id2:int>

    Returns the stored (or computed) data or None if parameters are invalid.
    """
    r = redis.Redis(decode_responses=True)
    if not force_refresh:
        data = r.get(watt_euros + "_" + str(sensor) + "_" + "by_id" + "_" +
                     str(id1) + "_" + str(id2))
        if data:
            # If found in cache, return it
            return json.loads(data)
Esempio n. 6
0
        if now > user.start_night_rate or now < user.end_night_rate:
            return 1
        else:
            return 0


def get_cw_sensor():
    """Returns the citizenwatt sensor object or None"""
    db = create_session()
    sensor = (db.query(database.Sensor).filter_by(name="CitizenWatt").first())
    db.close()
    return sensor


# Configuration
config = Config()

# DB initialization
database_url = (config.get("database_type") + "://" + config.get("username") +
                ":" + config.get("password") + "@" + config.get("host") + "/" +
                config.get("database"))
engine = create_engine(database_url, echo=config.get("debug"))
create_session = sessionmaker(bind=engine)
database.Base.metadata.create_all(engine)

sensor = get_cw_sensor()
while not sensor or not sensor.aes_key:
    tools.warning("Install is not complete ! " +
                  "Visit http://citizenwatt.local first.")
    time.sleep(1)
    sensor = get_cw_sensor()
Esempio n. 7
0
    login = post.get("login")
    user = db.query(database.User).filter_by(login=login).first()

    password = (
        config.get("salt") +
        hashlib.sha256(post.get("password", "").encode('utf-8')).hexdigest())
    if user and user.password == password:
        return True
    else:
        return False


# ===============
# Initializations
# ===============
config = Config()
#flag = True

logger.info(config.get("debug"))

database_url = (config.get("database_type") + "://" + config.get("username") +
                ":" + config.get("password") + "@" + config.get("host") + "/" +
                config.get("database"))

logger.info(database_url)

#engine = create_engine(database_url, echo=config.get("debug"))
engine = create_engine(
    "postgresql+psycopg2://citizenwatt:citizenwatt@localhost/citizenwatt")

logger.info(engine)
    if user is None:
        return -1
    elif user.end_night_rate > user.start_night_rate:
        if now > user.start_night_rate and now < user.end_night_rate:
            return 1
        else:
            return 0
    else:
        if now > user.start_night_rate or now < user.end_night_rate:
            return 1
        else:
            return 0


# Configuration
config = Config()

# DB initialization
database_url = (config.get("database_type") + "://" + config.get("username") + ":" +
                config.get("password") + "@" + config.get("host") + "/" +
                config.get("database"))
engine = create_engine(database_url, echo=config.get("debug"))
create_session = sessionmaker(bind=engine)
database.Base.metadata.create_all(engine)

try:
    while True:
        power = random.randint(0, 4000)
        power = math.sin(time.clock()*2)**2 * 2000
        print("New encrypted packet:" + str(power))