diff --git a/poc/py/state_to_buttons.py b/poc/py/state_to_buttons.py index dfd2d52..0bf2db0 100644 --- a/poc/py/state_to_buttons.py +++ b/poc/py/state_to_buttons.py @@ -4,24 +4,23 @@ from time import sleep def main(): args = get_args() + buckets = {} with open(args.p, "r") as f: f.seek(0, os.SEEK_END) while True: - line = f.readline() + line = f.readline().strip() + key = line.strip("/") if not line: - sleep(0.1) + sleep(0.25) continue - if line[0] == "T": - for char in args.b: - print(char) - else: - print("") - + if not key in buckets: + buckets[key] = False + buckets[key] = line[0] != "/" + print(sorted([int(i) for i in buckets if buckets[i]])) def get_args(): ap = argparse.ArgumentParser() ap.add_argument("-p", type=str, help="path to write out to", default="/tmp/cbappend.both.txt") - ap.add_argument("-b", type=str, help="keys to send while on", default="a") return ap.parse_args() if __name__ == "__main__": diff --git a/poc/py/test.sh b/poc/py/test.sh index 4015ffa..8b9b958 100644 --- a/poc/py/test.sh +++ b/poc/py/test.sh @@ -9,13 +9,12 @@ cleanup() { trap cleanup EXIT python3 ./state_to_buttons.py & - -( - while echo $((RANDOM%2)); do - if [ 0 == $((RANDOM%4)) ]; then - sleep 3 - fi - date >&2 +python3 testdata/rand_0_13_stream.py \ +| ( + while read -r line; do + #echo $line >&2 + echo $line done -) | python3 ./stream_to_state.py +) \ +| python3 ./stream_to_state.py