From e31ad590ccec89afe6bc94adb3c579e631db62df Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 11 Oct 2019 15:16:56 +0100 Subject: first version of bitbotctl - shows INFO logging --- bitbotctl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 bitbotctl (limited to 'bitbotctl') diff --git a/bitbotctl b/bitbotctl new file mode 100755 index 00000000..8fdb2817 --- /dev/null +++ b/bitbotctl @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +import argparse, os + +directory = os.path.dirname(os.path.realpath(__file__)) + +arg_parser = argparse.ArgumentParser( + description="BitBot CLI control utility") + +arg_parser.add_argument("--database", "-d", + help="Location of the sqlite3 database file", + default=os.path.join(directory, "databases", "bot.db")) + +args = arg_parser.parse_args() + +import json, socket + +sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +sock.connect("%s.sock" % args.database) +sock.send(b"0 version 0\n") +sock.send(b"1 log info\n") + +read_buffer = b"" + +while True: + data = sock.recv(1024) + if not data: + break + + data = read_buffer+data + lines = [line.strip(b"\r") for line in data.split(b"\n")] + read_buffer = lines.pop(-1) + for line in lines: + line = json.loads(line) + if line["action"] == "log": + print(line["data"]) -- cgit v1.3.1-10-gc9f91