Exemplo n.º 1
0
def get_compl_list(namelist):
    # namelist=get_list_names(listname)
    complete_list = {}
    # complete_list[JC.NAME]=listname

    rlist = {}
    for name in namelist:
        cat = wu.get_category(name)
        if cat is None:
            cat = 'None'
        if cat in rlist:
            # rlist[cat].append({name:su.get_selected_word_from_db(name,[JC.SHORTDEF])})
            rlist[cat].append({
                JC.NAME:
                name,
                JC.SHORTDEF:
                su.get_selected_word_from_db(name, [JC.SHORTDEF])[JC.SHORTDEF]
            })
        else:
            # rlist[cat]=[{name:su.get_selected_word_from_db(name,[JC.SHORTDEF])}]
            rlist[cat] = [{
                JC.NAME:
                name,
                JC.SHORTDEF:
                su.get_selected_word_from_db(name, [JC.SHORTDEF])[JC.SHORTDEF]
            }]
    # complete_list[JC.LIST]=rlist[JC.LIST]
    return rlist
Exemplo n.º 2
0
def add_words_to_list(list_name, word_list):
    try:
        in_valid_word_list = []
        for word in word_list:
            is_valid = su.search(word)
            if not is_valid:
                in_valid_word_list.append(word)
                word_list.remove(word)

        if len(in_valid_word_list) > 0:
            print('Unable to find following words: {0}'.format(
                in_valid_word_list))

        client = dbu.get_client()

        db = client[DC.DB_NAME]
        list_coll = db[DC.LISTS_COLL]

        list_update_query = {}
        list_update_query[JC.NAME] = list_name

        set_query = {}
        set_query[JC.PUSH] = {JC.LIST: {JC.EACH: word_list}}

        list_coll.update_one(list_update_query, set_query)
    except:
        traceback.print_exc()
    finally:
        client.close()
Exemplo n.º 3
0
def create(name, list):
    try:
        in_valid_word_list = []
        for word in list:
            is_valid = su.search(word)
            if not is_valid:
                in_valid_word_list.append(word)
                list.remove(word)

        if len(in_valid_word_list) > 0:
            print('Unable to find following words: {0}'.format(
                in_valid_word_list))

        client = dbu.get_client()

        db = client[DC.DB_NAME]
        list_coll = db[DC.LISTS_COLL]

        list_create_query = {}
        list_create_query[JC.NAME] = name
        list_create_query[JC.LIST] = get_compl_list(list)

        list_coll.insert_one(list_create_query)
        return True
    except:
        traceback.print_exc()
        return False
    finally:
        client.close()
Exemplo n.º 4
0
def word():
    word_name = request.args['name'].strip().lower()
    res = su.search(word_name)
    if res is None:
        return jsonify('{}')

    result = {}
    result[JC.NAME] = res[JC.ID]
    result[JC.SHORTDEF] = res[JC.SHORTDEF]
    return render_template('xsearch.html', result=result)
Exemplo n.º 5
0
def update_category(category_name, new_category_name, new_word_list):
    if not is_category_present(category_name):
        print("No category with name '{0}' is present in DB.".format(
            category_name))
        return False

    if category_name != new_category_name and is_category_present(
            new_category_name):
        print("Category with name '{0}' is already present in DB.".format(
            new_category_name))
        return False

    try:
        in_valid_word_list = []
        for word in new_word_list:
            is_valid = su.search(word)
            if not is_valid:
                in_valid_word_list.append(word)
                new_word_list.remove(word)

        if len(in_valid_word_list) > 0:
            print('Unable to find following words: {0}'.format(
                in_valid_word_list))

        client = dbu.get_client()

        db = client[DC.DB_NAME]
        category_coll = db[DC.CATEGORY_COLL]

        category_update_query = {}
        category_update_query[JC.NAME] = category_name

        new_data = {}
        # new_data[JC.PUSH] = {JC.LIST: {JC.EACH: word_list}}
        new_data[JC.NAME] = new_category_name
        new_data[JC.LIST] = new_word_list

        set_query = {}
        set_query[JC.SET] = new_data

        check_query = {}
        check_query[JC.UPSERT] = 'True'
        category_coll.update_one(category_update_query, set_query)

        listnames = wlu.get_refesh_list(new_word_list, category_name)
        for listname in listnames:
            wlu.refesh(listname)
        return True
    except:
        traceback.print_exc()
        return False
    finally:
        client.close()
Exemplo n.º 6
0
def get_compl_list(catname):
    catlist = get_category(catname)
    if catlist is None:
        return None
    catnames = catlist[JC.LIST]

    complete_list = []

    for name in catnames:
        word = su.get_selected_word_from_db(name, [JC.SHORTDEF])
        list = {}
        list[JC.NAME] = name
        list[JC.SHORTDEF] = word[JC.SHORTDEF]
        complete_list.append(list)

    return complete_list
Exemplo n.º 7
0
def run_test_suite():
    word = su.get_word_from_mw("abeeeeet")
    print(word)
Exemplo n.º 8
0
def get_word(word_name):
    result = su.search(word_name)
    if result is None:
        return jsonify('{}')
    res=jsonify(result)
    return res
Exemplo n.º 9
0
def is_valid_word(wordname):
    word = su.search(wordname)
    if word is None:
        return False
    return True