def make_todo_messages(self): ''' Take a formated SMS bank and create language specific todo files''' sms_bank = xl.load_workbook(self.paths.bank) try: final_wb = xl.load_workbook(self.paths.final) old_translations = sms.message_dict(final_wb.active,sms.FinalRow) except IOError as e: old_translations = None translations = sms.read_sms_bank(sms_bank,old_translations,'anc','postpartum','visits','special') print "Total Found: {} Todo: {}".format( len(translations), len([t for t in translations if t.is_todo()]) ) swahili_wb = make_language_todos(translations,'swahili') luo_wb = make_language_todos(translations,'luo') swahili_wb.save(self.paths.todo_swahili) luo_wb.save(self.paths.todo_luo) if self.options['copy']: swahili_copy_path = path_with_date(self.paths.todo_swahili) luo_copy_path = path_with_date(self.paths.todo_luo) swahili_wb.save(swahili_copy_path) luo_wb.save(luo_copy_path)
def test(self): final_wb = xl.load_workbook(self.paths.final) old_translations = sms.message_dict(final_wb.active, sms.FinalRow) print 'Count: {} Example: {!r}'.format( len(old_translations), old_translations.get(old_translations.keys()[0]))
def test(self): final_wb = xl.load_workbook(self.paths.final) old_translations = sms.message_dict(final_wb.active,sms.FinalRow) print 'Count: {} Example: {!r}'.format(len(old_translations),old_translations.get(old_translations.keys()[0]))
def make_final_messages(self): '''Take language specific todo files and done files and make a final translations file ''' # Load todo messages or fail try: todo_swahili_wb = xl.load_workbook(self.paths.todo_swahili) todo_luo_wb = xl.load_workbook(self.paths.todo_luo) except IOError as e: self.stderr.write('Error: Swahili and or Lue todo files not found') return todo_swahili_bank = sms.message_dict(todo_swahili_wb.active,sms.TranslationRow,language_name='swahili') todo_luo_bank = sms.message_dict(todo_luo_wb.active,sms.TranslationRow,language_name='luo') # Load done messages or fail try: done_swahili_wb = xl.load_workbook(self.paths.done_swahili) done_luo_wb = xl.load_workbook(self.paths.done_luo) except IOError as e: self.stderr.write('Error: Swahili and or Lue done files not found') return done_swahili_bank = sms.message_dict(done_swahili_wb.active,sms.TranslationRow,language_name='swahili') done_luo_bank = sms.message_dict(done_luo_wb.active,sms.TranslationRow,language_name='luo') # Load sms bank sms_bank = xl.load_workbook(self.paths.bank) translations = sms.read_sms_bank(sms_bank,None,'anc','special') # Create final wb and add header final_wb = xl.workbook.Workbook() new_ws = final_wb.active new_ws.append(sms.FinalRow.header) for msg in translations: description = msg.description() todo_swahili , todo_luo = todo_swahili_bank[description] , todo_luo_bank[description] done_swahili , done_luo = done_swahili_bank[description] , done_luo_bank[description] msg.swahili , msg.luo , msg.english = done_swahili.swahili , done_luo.luo , msg.new # Determine done status is_done_swahili = not done_swahili.is_todo() or todo_swahili.swahili != done_swahili.swahili is_done_luo = not done_luo.is_todo() or todo_luo.luo != done_luo.luo if not done_luo.is_todo() and not done_swahili.is_todo(): msg.status = 'clean' elif is_done_swahili and is_done_luo: msg.status = 'done' elif is_done_swahili: msg.status = 'swahili' elif is_done_luo: msg.status = 'luo' else: msg.status = 'todo' msg.configure_variables() new_ws.append(msg.get_final_row()) # Wrap text on english, swahili, luo columns last = new_ws.rows[-1] for i in [6,7,8]: last[i].alignment = WRAP_TEXT new_ws.freeze_panes = 'A2' new_ws.auto_filter.ref = 'A1:I1' column_widths = {'A':4,'D':6,'E':6,'F':6,'G':50,'H':50,'I':50} for col_letter, width in column_widths.items(): new_ws.column_dimensions[col_letter].width = width self.stdout.write('{} translations. {} todo.'.format( len(translations), len([m for m in translations if m.is_todo()]) ) ) final_wb.save(self.paths.final)