From f0f39693667a27963f3dc0a73af57065c0ae3bdd Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 5 Jul 2016 21:34:50 +0200 Subject: [PATCH] add runtime --- src/fenrir.py | 63 ++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/fenrir.py b/src/fenrir.py index d38ba956..41e0a541 100755 --- a/src/fenrir.py +++ b/src/fenrir.py @@ -7,36 +7,43 @@ import hashlib import difflib import textwrap import os +import speech.es as es + +runtime = { +'columns': 0, +'screenDriver': '/dev/vcsa3', +'delta': '', +'oldContentBytes': b'', +'oldContentText': '', +'oldContentAttrib': b'', +'newContentBytes': b'', +'newContentText': '', +'newContentAttrib': b'', +'speechDriverString':'es', +'speechDriver': es.speech() +} -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') + vcsa = open(runtime['screenDriver'],'rb') + runtime['newContentBytes'] = vcsa.read() + vcsa.close() + runtime['columns'] = int( runtime['newContentBytes'][1]) + runtime['newContentText'] = str(runtime['newContentBytes'][::2].decode('cp1252').encode('utf-8'))[7:] + runtime['newContentAttrib'] = runtime['newContentBytes'][1::2][7:] + print(runtime['newContentBytes'][9]) + #runtime['newContentString'] = str(runtime['newContentBytes'].decode('cp1252').encode('utf-8')) + runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns'])) + if runtime['oldContentBytes'] != runtime['newContentBytes']: + runtime['speechDriver'].stop() 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','') + '"') + + diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText']) + runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ ')) + + #print(runtime['delta']) + #runtime['speechDriver'].speak(runtime['delta']) - oldContentBytes = newContentBytes - oldContentString = newContentString + runtime['oldContentBytes'] = runtime['newContentBytes'] + runtime['oldContentText'] = runtime['newContentText'] + runtime['oldContentTextAttrib'] = runtime['newContentAttrib']