Ejemplo n.º 1
0
def cmd_add(word, input, priority):
    """Add a word into dict:

    \b
    WORD   the word that pointed by input
    INPUT  input character sequence
    PRIORITY sorting priority
    """
    print word, input, priority

    head, body = parser.parse_dict(EN_FILEPATH)

    ds = parser.DictSet(body)
    item = ds.get(input)
    confirmed = False
    if item:
        if click.confirm('Item already exists: {} {} {}, do you want to overwrite it?'.format(*item)):
            confirmed = True
    else:
        confirmed = True

    if confirmed:
        ds.add(word, input, priority)

    # Write back
    #with open('/tmp/a.txt', 'w') as f:
    with open(EN_FILEPATH, 'w') as f:
        f.writelines(
            itertools.chain(
                head,
                ds.iter_lines()
            )
        )
Ejemplo n.º 2
0
def cmd_list():
    head, body = parser.parse_dict(EN_FILEPATH)
    count = 0

    print 'All en words:'
    for line in body:
        word, input, priority = parser.parse_dict_line(line)
        if word:
            print '{}	{}'.format(word, input)
            count += 1
    print '\nTotal: {}'.format(count)