def act_edit(a): data = pickle_load(a) for i in list(data.keys()): print(i, data[i]) n = input("Select item number to edit: ") print (("Editing item: {}").format(data[int(n)])) act = input("Choose what to edit ([b]rand / [m]odel / [p]ower) ") if act == "p": p = input("Enter new power: ") data[int(n)].pop(2) data[int(n)].insert(2, int(p)) print ("Updated item: ", data[int(n)]) pickle_dump(a, data) elif act == "m": p = input("Enter new model: ") data[int(n)].pop(1) data[int(n)].insert(1, p) print ("Updated item: ", data[int(n)]) pickle_dump(a, data) elif act == "b": p = input("Enter new brand: ") data[int(n)].pop(0) data[int(n)].insert(0, p) print ("Updated item: ", data[int(n)]) pickle_dump(a, data) else: wrong_input()
def search_main(a): filter = input("Choose filter ([p]ower / [w]ord / [e]xactword) ") if filter == "p": filter2 = input("Power ([e]xact / [m]ore / [l]ess / [b]etween)? ") if filter2 == "e": sp = input("Exact power?") for i in list(pickle_load(a).values()): if i[2] == int(sp): best = i[2] print (i) elif filter2 == "m": search_more(a) elif filter2 == "l": search_less(a) elif filter2 == "b": search_between(a) else: wrong_input() elif filter == "w": word = input("Enter any word you wish: ") for i in list(pickle_load(a).values()): if i[0].lower().count(word.lower()) or i[1].lower().count(word.lower()): print (i) elif filter == "e": word = input("Enter exact word you wish: ") for i in list(pickle_load(a).values()): if i[0].lower() == word.lower() or i[1].lower() == word.lower(): print (i) else: wrong_input()
def act_edit(a): data = pickle_load(a) for i in list(data.keys()): print(i, data[i]) n = input("Select item number to edit: ") print(("Editing item: {}").format(data[int(n)])) act = input("Choose what to edit ([b]rand / [m]odel / [p]ower) ") if act == "p": p = input("Enter new power: ") data[int(n)].pop(2) data[int(n)].insert(2, int(p)) print("Updated item: ", data[int(n)]) pickle_dump(a, data) elif act == "m": p = input("Enter new model: ") data[int(n)].pop(1) data[int(n)].insert(1, p) print("Updated item: ", data[int(n)]) pickle_dump(a, data) elif act == "b": p = input("Enter new brand: ") data[int(n)].pop(0) data[int(n)].insert(0, p) print("Updated item: ", data[int(n)]) pickle_dump(a, data) else: wrong_input()
def search_main(a): filter = input("Choose filter ([p]ower / [w]ord / [e]xactword) ") if filter == "p": filter2 = input("Power ([e]xact / [m]ore / [l]ess / [b]etween)? ") if filter2 == "e": sp = input("Exact power?") for i in list(pickle_load(a).values()): if i[2] == int(sp): best = i[2] print(i) elif filter2 == "m": search_more(a) elif filter2 == "l": search_less(a) elif filter2 == "b": search_between(a) else: wrong_input() elif filter == "w": word = input("Enter any word you wish: ") for i in list(pickle_load(a).values()): if i[0].lower().count(word.lower()) or i[1].lower().count( word.lower()): print(i) elif filter == "e": word = input("Enter exact word you wish: ") for i in list(pickle_load(a).values()): if i[0].lower() == word.lower() or i[1].lower() == word.lower(): print(i) else: wrong_input()
# Operation body while True: if not os.path.exists("data.pickle"): pickle_dump("data.pickle", data) act = input_main() FUNCS = { "l": "act_list('data.pickle')", "d": "act_delete('data.pickle')", "e": "act_edit('data.pickle')", "s": "search_main('data.pickle')", "a": "act_add('data.pickle')", } if act in FUNCS.keys(): try: exec(FUNCS[act]) except: print("\n Lots of errors are still not processed \n Interrupts can injure db consistancy! Careful!") sys.exit(0) else: print("Congratiulations on no errors! :-)") finally: print(time.asctime()) elif act == "q": break else: wrong_input()
if not os.path.exists("data.pickle"): pickle_dump('data.pickle', data) act = input_main() FUNCS = { "l": "act_list('data.pickle')", "d": "act_delete('data.pickle')", "e": "act_edit('data.pickle')", "s": "search_main('data.pickle')", "a": "act_add('data.pickle')" } if act in FUNCS.keys(): try: exec(FUNCS[act]) except: print( "\n Lots of errors are still not processed \n Interrupts can injure db consistancy! Careful!" ) sys.exit(0) else: print("Congratiulations on no errors! :-)") finally: print(time.asctime()) elif act == "q": break else: wrong_input()