From 1a7746ddd89fd6e572f45d63d2ceb769b3753272 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 5 Jul 2016 00:16:22 +0200 Subject: [PATCH] add femir.py initial --- src/fenrir.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 src/fenrir.py diff --git a/src/fenrir.py b/src/fenrir.py new file mode 100755 index 00000000..d246e247 --- /dev/null +++ b/src/fenrir.py @@ -0,0 +1,38 @@ +#!/bin/python +import hashlib +import difflib +import textwrap +import os + +oldContentBytes = bytes() +oldContentString = '' +while(True): + vcs = open('/dev/vcs3','rb') + newContentBytes = vcs.read() + vcs.close() + newContentString = str(newContentBytes.decode('cp1252').encode('utf-8')) + newContentString = '\n'.join(textwrap.wrap(newContentString, 80)) +# if oldContentBytes == b'': +# oldContentBytes = newContentBytes +# oldContentString = newContentString + if oldContentBytes != newContentBytes: + os.system('killall espeak') + print("tty3 changed") + print("old content hash " + hashlib.sha256(str(oldContentBytes).encode('utf-8')).hexdigest()) + print("new content hash " + hashlib.sha256(str(newContentBytes).encode('utf-8')).hexdigest()) + ''' + for i, c in enumerate(newContent): + if c != oldContent[i]: + changedContent = newContent[i:] + break + ''' + diff = difflib.ndiff(oldContentString, newContentString) + delta = ''.join(x[2:] for x in diff if x.startswith('+ ')) + print("whats new") + print(delta) + os.system('espeak -v de ' + '"' + delta.replace('\n','').replace('"','').replace('-','') + '"&') + #os.system('spd-say ' + '"' + delta.replace('\n','') + '"') + + oldContentBytes = newContentBytes + oldContentString = newContentString +