Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument("--data", required=True)
    parser.add_argument("--output-dir", required=True)
    parser.add_argument("--hours", type=int, default=24)

    config, args = init(__name__, parser, fullconfig=True)

    # this config file structure is a f*****g nightmare
    recent_temps = get_recent(config['temper_sub']['state_file'],
                              grace=args.hours*60 + 120)
    count = len(recent_temps)
    logger.debug(f"found {count} recent measurements")


    # data = read_data(args.data, args.hours, count)
    # out = os.path.join(args.output_dir, f"plot-{args.hours}.png")
    # make_graph(recent_temps.keys(), data, out, args.hours)

    #for name in recent_temps.keys():
    #    data = read_data(args.data, args.hours, count)
    #    out = os.path.join(args.output_dir, f"{name}-{args.hours}.png")
    #    make_graph(name, data[name], out)
    data = read_data(args.data, args.hours, count)
    out = os.path.join(args.output_dir, f"plot-{args.hours}.png")
    make_graph(data, out)
Ejemplo n.º 2
0
def main():
    config = init(__name__)

    frontend_addr = config['zmq_frontend']
    backend_addr = config['zmq_backend']

    return simplepirate(frontend_addr, backend_addr)
Ejemplo n.º 3
0
def main():
    parser = ArgumentParser(add_help=False)
    parser.add_argument("-m", "--router-mandatory", action="store_true")
    config, args = init(__name__, parser)

    zmq_listen = config['zmq_listen']

    broker = Broker(args.router_mandatory)
    broker.bind(zmq_listen)
    return broker.mediate()
Ejemplo n.º 4
0
def main():
    parser = ArgumentParser(add_help=False)
    parser.add_argument("-m", "--router-mandatory", action="store_true")
    config, args = init(__name__, parser)

    frontend_addr = config['zmq_frontend']
    backend_addr = config['zmq_backend']

    md = MajorDomo(args.router_mandatory)
    md.bind(frontend_addr, backend_addr)
    return md.mediate()
Ejemplo n.º 5
0
def main():
    config = init("temps", fullconfig=True)

    # terrible config format, bad programmer!
    state = config['temper_sub']['state_file']

    logger.debug(f"state file: '{state}'")

    for name, values in get_recent(state).items():
        temp = values['temp']
        logger.info(f"{name}: {temp}C")
Ejemplo n.º 6
0
def main():
    #config = init(__name__)
    config = init("temper_sub")

    addr = config['addr']
    timeout = config.get("timeout", 1000 * 60 * 5)  # 5 minutes
    max_delay = config.get('max_delay', 2)  # seconds

    while True:
        # endless loop to handle reconnects
        try:
            notifier(addr, timeout, max_delay)
        except zmq.error.Again:
            logger.info("reconnecting after 10 seconds")
            sleep(10.0)
            continue
Ejemplo n.º 7
0
def main():
    config = init(__name__, fullconfig=True)

    retries = 10
    retry_sleep = 60
    for _ in range(retries):
        try:
            logger.info("starting telegram listener..")
            listener.listener(config)
            logger.info("Exiting..")
            sys.exit(0)
        except NetworkError as e:
            logger.warning(f"start failed: '{e.message}', retrying..")
            sleep(retry_sleep)
            continue

    else:
        logger.error(f"giving up after {retries} tries.")
Ejemplo n.º 8
0
def main():
    parser = argparse.ArgumentParser(
        description="Send messages with as @sudoisbot", add_help=False)
    parser.add_argument("message",
                        help="Message to send, read stdin otherwise",
                        nargs='?')
    parser.add_argument("-m", action="store_true", help="ignored, legacy")
    parser.add_argument(
        "-t",
        "--to",
        help="Whom to message, send to myself if not otherwise specified",
    )
    parser.add_argument("--code",
                        help="format markdown as code",
                        action='store_true',
                        default=False)
    config, args = init("telegram", parser)

    if not args.message and args.code:
        parser.error("--code not valid when using stdin")

    # use position arg if given, otherwise use stdin
    if args.message:
        if args.code:
            text = codeblock(args.message)
        else:
            text = args.message
    elif args.m:
        text = "-m"
    else:
        stdin = fileinput.input('-')
        text = codeblock("\n".join(stdin))

    # use --to if given, or send to me
    if args.to:
        send_msg(args.to, text)
    else:
        send_to_me(text)
Ejemplo n.º 9
0
def main():
    config = init(__name__)
    dealer = config['dealer']

    sendtelegram_rep(dealer)
Ejemplo n.º 10
0
#!/usr/bin/python3

import time

import zmq
from loguru import logger

from sudoisbot.common import init

if __name__ == "__main__":

    config = init('pubtest',  fullconfig=True)
    topic = b"test"

    context = zmq.Context()
    socket = context.socket(zmq.PUB)

    addr = config['temper_pub']['addr']
    socket.connect(addr)
    logger.info(f"connected to '{addr}'")

    for _ in range(20):
        msg = [topic, b"testing multipart send"]

        result = socket.send_multipart(msg)
        logger.info(result)

        try:
            time.sleep(0.5)
        except KeyboardInterrupt:
            socket.close()
Ejemplo n.º 11
0
from datetime import datetime

from loguru import logger
from playhouse.db_url import connect
from peewee import IntegrityError

from sudoisbot.sink import models
from sudoisbot.common import init

if __name__ == "__main__":
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument("--csv", required=True)
    parser.add_argument("--db", required=True)
    parser.add_argument("--ignore-dup", action="store_true")

    config, args = init("csv2db", parser, fullconfig=True)

    db = connect(args.db)
    models.db.initialize(db)
    #models.Temps.bind(db)

    imported = list()
    dups = list()

    name_input = ""

    with models.db:
        with open(args.csv, 'r') as f:
            for line in f.readlines():
                d = dict()
                items = line.strip().split(",")