add runtime
This commit is contained in:
parent
615ee2e90c
commit
f0f3969366
@ -7,36 +7,43 @@ import hashlib
|
|||||||
import difflib
|
import difflib
|
||||||
import textwrap
|
import textwrap
|
||||||
import os
|
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):
|
while(True):
|
||||||
vcs = open('/dev/vcs3','rb')
|
vcsa = open(runtime['screenDriver'],'rb')
|
||||||
newContentBytes = vcs.read()
|
runtime['newContentBytes'] = vcsa.read()
|
||||||
vcs.close()
|
vcsa.close()
|
||||||
newContentString = str(newContentBytes.decode('cp1252').encode('utf-8'))
|
runtime['columns'] = int( runtime['newContentBytes'][1])
|
||||||
newContentString = '\n'.join(textwrap.wrap(newContentString, 80))
|
runtime['newContentText'] = str(runtime['newContentBytes'][::2].decode('cp1252').encode('utf-8'))[7:]
|
||||||
# if oldContentBytes == b'':
|
runtime['newContentAttrib'] = runtime['newContentBytes'][1::2][7:]
|
||||||
# oldContentBytes = newContentBytes
|
print(runtime['newContentBytes'][9])
|
||||||
# oldContentString = newContentString
|
#runtime['newContentString'] = str(runtime['newContentBytes'].decode('cp1252').encode('utf-8'))
|
||||||
if oldContentBytes != newContentBytes:
|
runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns']))
|
||||||
os.system('killall espeak')
|
if runtime['oldContentBytes'] != runtime['newContentBytes']:
|
||||||
|
runtime['speechDriver'].stop()
|
||||||
print("tty3 changed")
|
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
|
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
|
||||||
oldContentString = newContentString
|
runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
|
||||||
|
|
||||||
|
#print(runtime['delta'])
|
||||||
|
#runtime['speechDriver'].speak(runtime['delta'])
|
||||||
|
|
||||||
|
runtime['oldContentBytes'] = runtime['newContentBytes']
|
||||||
|
runtime['oldContentText'] = runtime['newContentText']
|
||||||
|
runtime['oldContentTextAttrib'] = runtime['newContentAttrib']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user