Example #1
0
def read_vocab():
    """Loops forever and appends data to the xml root until the user
    exits the program."""
    global XML_ROOT
    while 1:
        try:
            eng_def = read_eng()
            jp_def = furi_cre.get_list()
            group = read_group()
            if group == '':
                adj = read_adj()
            else:
                adj = ''
            xml_def = def_to_xml(eng_def,jp_def,group, adj)
            XML_HAND.add_element(xml_def)
            print 'Definition received.'
        except KeyboardInterrupt:
            XML_HAND.save_file()
            sys.exit(1)
        except Exception:
            print 'Something went wrong. Saving file and exiting.'
            exc_type, exc_value, exc_traceback = sys.exc_info()
            XML_HAND.save_file()
            traceback.print_exception(exc_type, exc_value, exc_traceback)
            sys.exit(1)
Example #2
0
def read_data():
    """Reads a set of data required to make up the definition of a kanji"""
    kanji = raw_input('Enter kanji.\n') # Kanji for the flashcard
    meanings = raw_input('Enter meanings separated by spaces.  If a definition has spaces, use underscores (_) instead.\n') # Meanings of the kanji in english
    #readings = raw_input('Enter readings of the kanji in hiragana or katakana, separated by spaces.  Inserting a backslash between two similar readings will separate them.\n') # Readings of kanji in hiragana for kun and katakana for on
    print 'If a reading has kanji that lead into it, use a \"-\".  For furigana separation, use \'--\'.  For kanji which have kanji that follow, use \'---\'.'
    kun = raw_input('Enter kun reading of the kanji in the hepburn romanisation, separated by spaces.  Leave blank if there is none.\n') # kun readings of kanji
    on = raw_input('Enter on reading of the kanji in hepburn romanisation, separated by spaces.  Leave blank if there is none.\n') # on reading of the kanji
    kun = r_conv.to_hiragana(kun) # converts hepburn to hiragana
    on = r_conv.to_katakana(on) # converts hepburn to katakana
    if len(kun) == 0:
        readings = on
    elif len(on) == 0:
        readings = kun
    elif len(on) == 0 and len(kun) == 0:
        print 'You\'ve not entered a reading.  Have another go.'
        return read_data()
    else:
        readings = kun + ' ' + on
    # This is the part that does the most work.
    print 'Enter compounds for the kanji.'
    #####ONLY READS ONE DEFINITION - FIX THIS#####
    k_comp = furi_cre.get_list()
    definitions = []
    definitions.extend([kanji, meanings, readings, k_comp])
    print 'Definition added: \n%s'%(definitions)
    return definitions