diff --git a/poc/py/requirements.txt b/poc/py/requirements.txt new file mode 100644 index 0000000..1f21f99 --- /dev/null +++ b/poc/py/requirements.txt @@ -0,0 +1 @@ +pyautogui diff --git a/poc/py/state_to_buttons.py b/poc/py/state_to_buttons.py new file mode 100644 index 0000000..dfd2d52 --- /dev/null +++ b/poc/py/state_to_buttons.py @@ -0,0 +1,28 @@ +import argparse +import os +from time import sleep + +def main(): + args = get_args() + with open(args.p, "r") as f: + f.seek(0, os.SEEK_END) + while True: + line = f.readline() + if not line: + sleep(0.1) + continue + if line[0] == "T": + for char in args.b: + print(char) + else: + print("") + + +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__": + main() diff --git a/poc/py/test.sh b/poc/py/test.sh index b442c18..726028d 100644 --- a/poc/py/test.sh +++ b/poc/py/test.sh @@ -1,13 +1,21 @@ #! /bin/bash +set -e +set -o pipefail + +cleanup() { + kill -9 $(jobs -p) || true +} +trap cleanup EXIT + +python3 ./state_to_buttons.py & + ( - for j in `seq 1 10`; do - for i in `seq 1 10`; do - echo $i - true || printf "$j/$i " >&2 - if ((i%j==0)); then - sleep $j - fi - done + while echo ""; do + if [ 0 == $((RANDOM%4)) ]; then + sleep 3 + fi + date >&2 done -) | python3 ./stream_to_state.py +) | python3 ./stream_to_state.py +