41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import argparse
|
|
import os
|
|
from time import sleep
|
|
|
|
import buttons
|
|
print(buttons.keys)
|
|
|
|
def main():
|
|
args = get_args()
|
|
buckets = {}
|
|
with open(args.p, "r") as f:
|
|
f.seek(0, os.SEEK_END)
|
|
while True:
|
|
line = f.readline().strip()
|
|
if not line:
|
|
sleep(0.25)
|
|
continue
|
|
key = line.strip("/").split()[0]
|
|
if not key in buckets:
|
|
buckets[key] = [False, len(buckets)]
|
|
buckets[key][0] = False if line[0] == "/" else float(line.split()[-1])
|
|
for key in buckets:
|
|
keyindex = buckets[key][1]
|
|
keycode = list(sorted(buttons.keys.keys()))[keyindex]
|
|
keyname = buttons.keys[keycode]
|
|
if buckets[key][0]:
|
|
print(f"+{key}({keyname})", end=" ")
|
|
buttons.down(keycode)
|
|
else:
|
|
print(f"-{key}({keyname})", end=" ")
|
|
buttons.up(keycode)
|
|
print()
|
|
|
|
def get_args():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("-p", type=str, help="path to write out to", default="/tmp/cbappend.both.txt")
|
|
return ap.parse_args()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|