def delete_category(category_name): try: client = dbu.get_client() db = client[DC.DB_NAME] category_coll = db[DC.CATEGORY_COLL] # words_coll = db[DC.WORDS_COLL] # # word_update_query = {} # word_update_query[JC.CATEGORY] = category_name # # new_values = {} # new_values[JC.CATEGORY] = "" # # set_query = {} # set_query[JC.SET] = new_values # words_coll.update_one(word_update_query,set_query) delete_query = {} delete_query[JC.NAME] = category_name cat = get_category(category_name) catlist = cat[JC.LIST] category_coll.delete_one(delete_query) listnames = wlu.get_refesh_list(catlist, category_name) for listname in listnames: wlu.refesh(listname) except: traceback.print_exc() finally: client.close()
def add_list(): list_name = request.form['listname'].strip().lower() liststr = request.form['list'] result = {} result['name'] = list_name result['list'] = liststr if len(list_name) == 0 or len(liststr) == 0: result['error'] = RC.MISSING_DATA return render_template('addlist.html', result=result) if wlu.is_list_present(list_name): result['error'] = RC.LIST_ALREADY_PRESENT return render_template('addlist.html', result=result) list = [] for word in liststr.split(','): list.append(word.strip().lower()) validatelist = wu.validate_wordlist(list) if len(validatelist[JC.INVALID_LIST]) > 0: result['error'] = [ 'Invalid words: {0}'.format(validatelist[JC.INVALID_LIST]) ] return render_template('addlist.html', result=result) result = wlu.create(list_name, validatelist[JC.VALID_LIST]) if result is False: result['error'] = RC.UNSUCCESSFUL_OPERATION return render_template('addlist.html', result=result) return redirect(url_for('lists'))
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()
def export_list(listname): try: word_list = wu.get_list(listname) # for word in self.list: # is_valid = su.search(word) # if not is_valid: # in_valid_word_list.append(word) # self.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] words_coll = db[DC.WORDS_COLL] list_search_query = {} list_search_query[JC.ID] = {JC.IN: word_list} result = words_coll.find(list_search_query) for words in result: print(words['shortdef']) except: traceback.print_exc() finally: client.close()
def xlists(list_name): # result=wlu.get_compl_list(list_name) # result={'name': 'globalizer-1', 'list': {'feeling embarrased': [{'name': 'abash', 'shortdef': ['to destroy the self-control or self-confidence of']}, {'name': 'chagrin', 'shortdef': ['a feeling of being annoyed by failure or disappointment']}, {'name': 'disconcert', 'shortdef': ['to disturb the arrangement of : upset', 'to disturb the self-control of']}], 'abnormal': [{'name': 'aberrant', 'shortdef': ['being different from the usual or natural type']}, {'name': 'anomalous', 'shortdef': ['not following a general rule or method : irregular unusual']}, {'name': 'anomaly', 'shortdef': ['an act or instance of not following the general rule or method', 'something anomalous : something different, abnormal, strange, or not easily described']}, {'name': 'atypical', 'shortdef': ['not typical : irregular']}, {'name': 'erratic', 'shortdef': ['marked by lack of consistency or regularity', 'not of the usual or normal kind : eccentric']}], 'supporting in something wrong': [{'name': 'abet', 'shortdef': ['to actively encourage or aid']}, {'name': 'accomplice', 'shortdef': ['someone associated with another in wrongdoing']}, {'name': 'collusion', 'shortdef': ['secret agreement or cooperation for an illegal or dishonest purpose']}, {'name': 'connive', 'shortdef': ['to cooperate secretly or have a secret understanding']}], 'None': [{'name': 'abeyance', 'shortdef': ['a temporary interruption of activity']}, {'name': 'dormant', 'shortdef': ['not active but capable of becoming active', 'sleeping or appearing to be asleep : sluggish', 'having growth or other biological activity much reduced or suspended']}]}} result = wlu.get_list(list_name) print(result) name = result[JC.NAME] list = result[JC.LIST] res = (name, list) return render_template('xlists.html', result=result)
def update_listview(list_name): list = wlu.get_list_names(list_name) liststr = list[0] for word in list[1:]: liststr += ', ' + word result = {} result['oldlistname'] = list_name result['newlistname'] = list_name result['list'] = liststr print(result) return render_template('updatelist.html', result=result)
def update_list(): old_list_name = request.form['oldlistname'].strip().lower() new_list_name = request.form['newlistname'].strip().lower() liststr = request.form['list'] result = {} result['oldlistname'] = old_list_name result['newlistname'] = new_list_name result['list'] = liststr if len(new_list_name) == 0 or len(liststr) == 0: result['error'] = RC.MISSING_DATA return render_template('updatelist.html', result=result) if new_list_name != old_list_name and wlu.is_list_present(new_list_name): result['error'] = RC.CATEGORY_ALREADY_PRESENT return render_template('updatelist.html', result=result) if not wlu.is_list_present(old_list_name): result['error'] = RC.CATEGORY_NOT_FOUND return render_template('updatelist.html', result=result) list = [] for word in liststr.split(','): list.append(word.strip().lower()) validatelist = wu.validate_wordlist(list) if len(validatelist[JC.INVALID_LIST]) > 0: result['error'] = [ 'Invalid words: {0}'.format(validatelist[JC.INVALID_LIST]) ] return render_template('updatelist.html', result=result) result = wlu.update_list(old_list_name, new_list_name, validatelist[JC.VALID_LIST]) if result is None: result['error'] = RC.UNSUCCESSFUL_OPERATION return render_template('updatelist.html', result=result) return redirect(url_for('xlists', list_name=new_list_name))
def create(self): result = self.add_word() try: client = dbu.get_client() db = client[DC.DB_NAME] category_coll = db[DC.CATEGORY_COLL] search_query = {} search_query[JC.NAME] = self.name category_data = {} # category_data[JC.ID] = self.name category_data[JC.NAME] = self.name category_data[JC.LIST] = self.list if category_coll.count_documents(search_query) == 0: category_coll.insert_one(category_data) # listnames = wlu.get_refesh_list(self.list) # for listname in listnames: # wlu.refesh(listname) # return True, result else: category_coll.replace_one(search_query, category_data) listnames = wlu.get_refesh_list(self.list, 'None') for listname in listnames: wlu.refesh(listname) return True, result except Exception as exception: traceback.print_exc() return False, result finally: client.close() # cat=Category('testcat2', ['abate','axiom', 'ggg','dictum']) # print(cat.create())
def update_category(): if not (request.headers['Content-Type'] == 'application/json'): return RC.INVALID_CONTENT_TYPE payload = json.dumps(request.json) name=payload['name'] list=wlu.generate_list(payload['list']) result=cu.update_category(name,list) if not result: return RC.UNSUCCESSFUL_OPERATION return result
def create_category(): if not (request.headers['Content-Type'] == 'application/json'): return RC.INVALID_CONTENT_TYPE payload = json.dumps(request.json) name=payload['name'] list=wlu.generate_list(payload['list']) cat=cf.Category(name,list) is_successfull, result=cat.create() if not is_successfull: return RC.UNSUCCESSFUL_OPERATION return result
def lists(): list = wlu.get_lists() return render_template('lists.html', list=list)
def delete_list(list_name): wlu.delete_list(list_name) return redirect(url_for('lists'))
def get_list(list_name): result = wlu.get_compl_list(list_name) if result is None: return jsonify('{}') res=jsonify(result) return res
def __init__(self, name, list): self.name = str.lower(name) self.list = wlu.sanatize_List(list)