-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.py
31 lines (23 loc) · 928 Bytes
/
log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
import datetime
import threading
from talon import app, ui
from talon.engine import engine
from talon.voice import Word, Context, Rep, Str, press
from talon_init import TALON_HOME, TALON_PLUGINS, TALON_USER
phrase_lock = threading.Lock()
context = Context('log')
class Logger:
def __init__(self):
self.lock = threading.Lock()
ts = time.time()
self.timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S')
self.file_name = '%s/%s.log' % (TALON_HOME, self.timestamp)
def on_phrase(self, m):
# if m['cmd'] in ('p.begin', 'p.end') and m['grammar'] == 'talon':
if m['cmd'] in ('p.end') and m['grammar'] == 'talon':
with self.lock:
with open(self.file_name, 'a') as log_file:
log_file.write('%s\n' % ' '.join(m['phrase']))
# logger = Logger()
# engine.register('phrase', logger.on_phrase)