Browse Source

added -H Num to keep track of blather history

this shit is untested!
Jezra 11 years ago
parent
commit
2888974007
1 changed files with 24 additions and 0 deletions
  1. 24
    0
      Blather.py

+ 24
- 0
Blather.py View File

@@ -16,6 +16,7 @@ conf_dir = os.path.expanduser("~/.config/blather")
16 16
 lang_dir = os.path.join(conf_dir, "language")
17 17
 command_file = os.path.join(conf_dir, "commands")
18 18
 strings_file = os.path.join(conf_dir, "sentences.corpus")
19
+history_file = os.path.join(conf_dir, "blather.history")
19 20
 lang_file = os.path.join(lang_dir,'lm')
20 21
 dic_file = os.path.join(lang_dir,'dic')
21 22
 #make the lang_dir if it doesn't exist
@@ -27,6 +28,8 @@ class Blather:
27 28
 		#import the recognizer so Gst doesn't clobber our -h
28 29
 		from Recognizer import Recognizer
29 30
 		self.ui = None
31
+		#keep track of the opts
32
+		self.opts = opts
30 33
 		ui_continuous_listen = False
31 34
 		self.continuous_listen = False
32 35
 		self.commands = {}
@@ -46,6 +49,10 @@ class Blather:
46 49
 				
47 50
 			self.ui = UI(args,opts.continuous)
48 51
 			self.ui.connect("command", self.process_command)
52
+		
53
+		if self.opts.history:
54
+			self.history = []
55
+		
49 56
 					
50 57
 	def read_commands(self):
51 58
 		#read the.commands file
@@ -65,6 +72,19 @@ class Blather:
65 72
 		#close the strings file
66 73
 		strings.close()
67 74
 	
75
+	def log_history(self,text):
76
+		if self.opts.history:
77
+			self.history.append(text)
78
+			if len(self.history) > self.opts.history:
79
+				#pop off the first item
80
+				self.history.pop(0)
81
+			
82
+			#open and truncate the blather history file
83
+			hfile = open(history_file, "w")
84
+			for line in self.history:
85
+				hfile.write( line+"\n")
86
+			#close the  file
87
+			hfile.close()
68 88
 	
69 89
 	def recognizer_finished(self, recognizer, text):
70 90
 		t = text.lower()
@@ -73,6 +93,7 @@ class Blather:
73 93
 			cmd = self.commands[t]
74 94
 			print cmd
75 95
 			subprocess.call(cmd, shell=True)
96
+			self.log_history(text)
76 97
 		else:
77 98
 			print "no matching command"
78 99
 		#if there is a UI and we are not continuous listen
@@ -117,6 +138,9 @@ if __name__ == "__main__":
117 138
 	parser.add_option("-c", "--continuous",
118 139
 		action="store_true", dest="continuous", default=False,
119 140
 		help="starts interface with 'continuous' listen enabled")
141
+	parser.add_option("-H", "--history", type="int",
142
+		action="store", dest="history", 	
143
+		help="number of commands to store in history file")
120 144
 
121 145
 	(options, args) = parser.parse_args()
122 146
 	#make our blather object

Loading…
Cancel
Save