def search_database(word):
    '''offline search.'''

    conn = sqlite3.connect(os.path.join(DEFAULT_PATH, 'word.db'))
    curs = conn.cursor()
    curs.execute(r'SELECT expl, pr FROM Word WHERE name LIKE "%s%%"' % word)
    res = curs.fetchall()
    if res:
        print(colored(word + ' 在数据库中存在', 'white', 'on_green'))
        print()
        print(colored('★ ' * res[0][1], 'red'), colored('☆ ' * (5 - res[0][1]), 'yellow'), sep='')
        colorful_print(res[0][0])
    else:
        print(colored(word + ' 不在本地，从有道词典查询', 'white', 'on_red'))
        search_online(word)
        input_msg = '若存入本地，请输入优先级(1~5) ，否则 Enter 跳过\n>>> '
        if sys.version_info[0] == 2:
            add_in_db_pr = raw_input(input_msg)
        else:
            add_in_db_pr = input(input_msg)

        if add_in_db_pr and add_in_db_pr.isdigit():
            if(int(add_in_db_pr) >= 1 and int(add_in_db_pr) <= 5):
                add_word(word, int(add_in_db_pr))
                print(colored('单词 {word} 已加入数据库中'.format(word=word), 'white', 'on_red'))
    curs.close()
    conn.close()
def search_database ( word ) : conn = sqlite3 . connect ( os . path . join ( DEFAULT_PATH , 'word.db' ) ) curs = conn . cursor ( ) curs . execute ( r'SELECT expl, pr FROM Word WHERE name LIKE "%s%%"' % word ) res = curs . fetchall ( ) if res : print ( colored ( word + ' 在数据库中存在' , 'white' , 'on_green' ) ) print ( ) print ( colored ( '★ ' * res [ 0 ] [ 1 ] , 'red' ) , colored ( '☆ ' * ( 5 - res [ 0 ] [ 1 ] ) , 'yellow' ) , sep = '' ) colorful_print ( res [ 0 ] [ 0 ] ) else : print ( colored ( word + ' 不在本地，从有道词典查询' , 'white' , 'on_red' ) ) search_online ( word ) input_msg = '若存入本地，请输入优先级(1~5) ，否则 Enter 跳过\n>>> ' if sys . version_info [ 0 ] == 2 : add_in_db_pr = raw_input ( input_msg ) else : add_in_db_pr = input ( input_msg ) if add_in_db_pr and add_in_db_pr . isdigit ( ) : if ( int ( add_in_db_pr ) >= 1 and int ( add_in_db_pr ) <= 5 ) : add_word ( word , int ( add_in_db_pr ) ) print ( colored ( '单词 {word} 已加入数据库中' . format ( word = word ) , 'white' , 'on_red' ) ) curs . close ( ) conn . close ( )
offline search.