#r'c:\program files\bozzy\' #File name: bozzy.py #Final working version: 1/14/2007 import string import os import time import sys # Converts raw steno into rtf/cre format def rtf_convert(steno_entry): steno_entry = steno_entry.replace(r'] [',r'/') steno_entry = steno_entry.replace(r'[','') steno_entry = steno_entry.replace(r']','') dic_entry = os.path.join(boilerp_pre + steno_entry + r'}' + line + boilerp_post + boilerp_time + '}') rtf_dic.write(dic_entry) # Allows user to enter another stroke for the same word def again_loop(): entry_status = True while entry_status == True: global steno_entry print line steno_entry = raw_input(r'steno:''') if steno_entry == ' quit': clean_up() elif steno_entry == ' skip': break elif steno_entry == '': print line steno_entry = raw_input(r'steno:''') print steno_entry + ' ' + line decide_entry = raw_input(r'next, again, delete:''') if decide_entry == ' next': rtf_convert(steno_entry) entry_status = False elif decide_entry == ' again': rtf_convert(steno_entry) continue elif decide_entry == ' delete': delete_loop() entry_status = False elif decide_entry == ' quit': clean_up() elif decide_entry == ' skip': break else: rtf_convert(steno_entry) entry_status = False # Re-displays word without converting previous stroke def delete_loop(): entry_status = True while entry_status == True: global steno_entry print line steno_entry = raw_input(r'steno:''') if steno_entry == ' quit': clean_up() elif steno_entry == ' skip': break elif steno_entry == '': print line steno_entry = raw_input(r'steno:''') print steno_entry + ' ' + line decide_entry = raw_input(r'next, again, delete:''') if decide_entry == ' next': rtf_convert(steno_entry) entry_status = False elif decide_entry == ' again': rtf_convert(steno_entry) again_loop() entry_status = False elif decide_entry == ' delete': continue elif decide_entry == ' quit': clean_up() elif decide_entry == ' skip': break else: rtf_convert(steno_entry) entry_status = False def clean_up(): rtf_dic.close() os.rename(r'c:\program files\bozzy\bozzy.rtf',time.strftime('%m%d%y%H%M%S') + '.rtf') # Saves user's place for next session last_read = str(line) last_read = last_read.strip() bozzy_ini = open(r'c:\program files\bozzy\bozzy.ini','w') bozzy_ini.write(last_read) bozzy_ini.close() print 'Quitting' sys.exit() rtf_dic = file(r'c:\program files\bozzy\bozzy.rtf','w') # Goes at the beginning of every rtf/cre file boilerp_head = '''{\\rtf1\\ansi{\\*\\cxrev100}\\cxdict{\\*\\cxsystem Bozzy by Mirabai Knight}\\deff0{\\fonttbl {\\f0\\fmodern Courier New;}}{\\stylesheet{\\s0 Normal;}{\\s1 Question; }{\\s2 Answer;}{\\s3 Colloquy;}}{\\*\\cxtranopt\\numbar}''' rtf_dic.write(boilerp_head) # Standard rtf/cre markup boilerp_pre = '{\\*\\cxs ' boilerp_post = '{\\*\\cxsvatdictentrydate\\' boilerp_time = time.strftime('\\yr%Y\\mo%m\\da%d') word_list = open(r'c:\program files\bozzy\wordlist.txt','r') try: bozzy_ini = open(r'c:\program files\bozzy\bozzy.ini','r') last_word = bozzy_ini.readline() bozzy_ini.close() except IOError: last_word = '' found = False for line in word_list: if last_word == '': found = True # Finds last word from previous session elif last_word == line or last_word + '\n' == line: print line steno_entry = raw_input(r'steno:''') # Note the space before each steno entry if steno_entry == ' quit': clean_up() elif steno_entry == ' skip': found = True continue elif steno_entry == '': print line steno_entry = raw_input(r'steno:''') print print steno_entry + ' ' + line decide_entry = raw_input(r'next, again, delete:''') if decide_entry == ' quit': clean_up() elif decide_entry == ' next': rtf_convert(steno_entry) elif decide_entry == ' again': rtf_convert(steno_entry) again_loop() elif decide_entry == ' delete': delete_loop() elif decide_entry == ' skip': pass else: rtf_convert(steno_entry) found = True continue elif not found: continue # Begins iteration through word list print line steno_entry = raw_input(r'steno:''') if steno_entry == ' quit': clean_up() elif steno_entry == ' skip': continue elif steno_entry == '': print line steno_entry = raw_input(r'steno:''') print print steno_entry + ' ' + line decide_entry = raw_input(r'next, again, delete:''') if decide_entry == ' quit': clean_up() elif decide_entry == ' next': rtf_convert(steno_entry) elif decide_entry == ' again': rtf_convert(steno_entry) again_loop() elif decide_entry == ' delete': delete_loop() elif decide_entry == ' skip': continue else: rtf_convert(steno_entry) print 'End of list' clean_up()