Esempio n. 1
0
def _post_snapshot(snap: dict, user: dict, host: str, port: int):
    snap['user_id'] = user['user_id']
    resp = requests.post(f'http://{host}:{port}/snapshot',
                         bson.encode(snap))
    if resp.status_code == 200:
        return
    logger.error(f'Failed to send snapshot to server \n\t> {resp.status_code}')
Esempio n. 2
0
def command_parse(field, filename):
    if not Path(filename).exists():
        logger.error(f'File {ansi.bold(filename)} does not exist')
        return

    if field not in parser:
        logger.error(f'Parser {ansi.bold(field)} does not exist')
        return

    with open(filename, 'rb') as f:
        data = f.read()

    print(parser[field](data))
Esempio n. 3
0
def command_run_parser(field, url):
    f_url = furl(url)
    scheme = f_url.scheme
    if scheme not in drivers:
        logger.error(f'Scheme {ansi.bold(scheme)} not supported')
        return

    driver = drivers[scheme](f_url.host, f_url.port)

    def handler(route, data):
        driver.publish_data(parser[field](data), 'thoughtinator.out', field)

    driver.consume_work(handler, 'thoughtinator.raw', field)
Esempio n. 4
0
def command_run_server(host, port, mqueue_url):
    url = furl(mqueue_url)
    if url.scheme not in drivers:
        logger.error(f'Scheme {ansi.bold(url.scheme)} is invalid')
    driver = drivers[url.scheme](url.host, url.port)

    def make_publish(*args):
        if len(args) < 3:
            return driver.publish_work(*args)
        return driver.publish_data(*args)

    endpoint = ServerEndpoint(make_publish)
    endpoint.run(host, port)
Esempio n. 5
0
    def load_config(self):
        from thoughtinator.utils.logger import error
        config_env = self.os['CONFIG_FILE']
        if config_env is None:
            config_path = self.root / 'config.json'
        else:
            config_path = Path(config_env)

        if not config_path.exists():
            error(f'Config file {config_path} does not exist')
            sys.exit()

        with open(config_path) as config_file:
            config_data = config_file.read()
        try:
            self.config = json.loads(config_data)
        except BaseException as e:
            error(f'Malformed config.json file \n\t> {str(e)}')
            sys.exit()
Esempio n. 6
0
def _post_user(user: dict, host: str, port: int):
    resp = requests.post(f'http://{host}:{port}/user',
                         bson.encode(user))
    if resp.status_code == 200:
        return
    logger.error(f'Failed to send user to server \n\t> {resp.status_code}')