2
2
version = '3.2'
3
3
testing = version [- 5 :] == 'debug'
4
4
if testing : import traceback
5
- from os import sep , path
5
+ from os import sep , path , system
6
6
import sys
7
7
8
8
from time import sleep
30
30
input ('include error ' + str (e ))
31
31
exit ()
32
32
33
+ class EmergencyStop (Exception ):
34
+ pass
33
35
34
36
class Entry :
35
37
'''stores an entry that the user makes'''
36
38
37
39
def __init__ (self , text :str = '' , time :datetime = None , intervals :list = None , printdate :bool = False ):
38
- '''set empty strings, initialize the filename taken from globals '''
40
+ '''set empty strings'''
39
41
self .text :str = text
40
-
41
- if time : self .time :datetime = time
42
- if intervals : self .intervals :list = intervals
42
+ self .time :datetime = time
43
+ self .intervals :list = intervals
43
44
self .printdate :bool = printdate
44
45
46
+ def __bool__ (self ):
47
+ return len (self .text ) > 0
48
+
45
49
def __str__ (self ):
46
50
'''
47
51
Convert user input information and returns data alone\n
@@ -64,19 +68,22 @@ def record(self):
64
68
65
69
while True :
66
70
#get pressed character
67
- char = str (getch ())[2 :- 1 ]
71
+ char = str (getch ())[2 :- 1 ]
68
72
69
73
#format time
70
74
t2 = datetime .now ().timestamp ()
71
- if (t2 - t1 )> 60 : t2 , t1 = (t2 - t1 )- int (t2 - t1 )+ 5 , t2
72
- else : t2 , t1 = t2 - t1 , t2
75
+ if (t2 - t1 ) > 60 :
76
+ t2 , t1 = (t2 - t1 ) - int (t2 - t1 ) + 5 , t2
77
+ else :
78
+ t2 , t1 = t2 - t1 , t2
73
79
t2 = round (t2 , 4 )
74
80
75
- #Return key pressed
76
- if char == '\\ r' :
81
+ #Return key
82
+ if char == '\\ r' :
77
83
78
84
#do nothing if text is empty
79
- if len (entry ) == 0 : continue
85
+ if len (entry ) == 0 :
86
+ continue
80
87
81
88
#add a new line character to the entry and format the entry object
82
89
entry .append (['\n ' , t2 ])
@@ -85,17 +92,17 @@ def record(self):
85
92
print ()
86
93
return self
87
94
88
- #Escape seq pressed
95
+ #Escape char
89
96
elif char == '\\ \\ ' :
90
97
print ('\\ ' , end = '' , flush = True )
91
98
char = "\\ "
92
99
93
- #Tabspace pressed
100
+ #Tabspace
94
101
elif char == '\\ t' :
95
102
print ('\t ' , end = '' , flush = True )
96
103
char = '\t '
97
104
98
- #Backspace pressed, I think
105
+ #Backspace?
99
106
elif char == '\\ x08' :
100
107
print ('\b \b ' , end = '' , flush = True )
101
108
char = '\b '
@@ -149,7 +156,8 @@ def add(self, *entries):
149
156
if f .tell ()== 0 :
150
157
f .writelines ([self .headerFormat % self .version ])
151
158
for entry in entries :
152
- f .write (self .entryFormat % (entry .time .ctime (), entry .text , str (entry .intervals )))
159
+ if entry :
160
+ f .write (self .entryFormat % (entry .time .ctime (), entry .text , str (entry .intervals )))
153
161
154
162
def record (self , entry :Entry = Entry ()):
155
163
'''
@@ -164,6 +172,8 @@ def record(self, entry:Entry=Entry()):
164
172
self .add (entry )
165
173
if self .sessionStopWord in str (entry ).lower ():
166
174
break
175
+ except EmergencyStop as e :
176
+ self .add (entry )
167
177
except Exception as e :
168
178
print ('your last entry : ' + str (entry ))
169
179
raise e
@@ -318,7 +328,7 @@ def diaryinfo():
318
328
319
329
#get cli args
320
330
cliargs = [arg .lower () for arg in sys .argv ][1 :]
321
- log ('cli args' , sys .argv , '->' , cliargs )
331
+ log ('DIARY cli args' , sys .argv , '->' , cliargs )
322
332
diary = Diary (filename = filename , typespeed = typespeed )
323
333
324
334
# parse cli args to select menu
0 commit comments