-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlookup_app.py
More file actions
123 lines (96 loc) · 3.16 KB
/
lookup_app.py
File metadata and controls
123 lines (96 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
The Lookup App
Dictionary for Quick Reference of Technology Terms
Lookup and add new definitions by keyword.
Author: Clinton Garwood
Date: November 2024
License: MIT
ChangeLog: Dictionary Values are appended with update method
"""
import os
import pickle
class Terms:
"""
CLASS Terms built from Design Document
"""
def __init__(self, term_keyword, as_defined):
self.term_name = term_keyword
self.definition = [as_defined]
def set_term_name(self, term_name):
self.term_name = term_name
def set_definition(self, new_define):
self.definition = new_define
def get_term_name(self):
return self.term_name
def get_definition(self):
return self.definition
def terms_menu():
print(f"\n\t1) Lookup a Term")
print(f"\t2) Add a Term")
print(f"\t3) Update a Term")
print(f"\t4) Exit")
return
def main():
print("\nTechnical Term Lookup App")
pickle_filename = 'terms_dict.pkl'
terms_dict = load_terms_dict(pickle_filename)
while True:
terms_menu()
user_choice = get_terms_choice()
if user_choice == '1':
get_term(terms_dict)
elif user_choice == '2':
add_term(terms_dict)
elif user_choice == '3':
update_term(terms_dict)
elif user_choice == '4':
save_terms_dict(terms_dict, pickle_filename)
print(f"\tExiting...")
break
else:
print(f"\tInvalid choice. Please select again.")
return
def load_terms_dict(filename):
if os.path.exists(filename):
with open(filename, 'rb') as read_file:
terms_dict = pickle.load(read_file)
print(f"\tLoaded terms from {filename}")
else:
terms_dict = {}
print(f"\tNo existing data found. Starting fresh.")
return terms_dict
def save_terms_dict(terms_dict, filename):
with open(filename, 'wb') as save_terms:
pickle.dump(terms_dict, save_terms)
print(f"\tData saved to {filename}")
return
def get_terms_choice():
user_choice = input("\tPlease select: ")
return user_choice
def add_term(terms_dict):
term_name = input(f"\tPlease enter the term-name: ").strip()
new_define = input(f"\tPlease enter the definition: ")
if term_name in terms_dict:
print(f"\tTerm {term_name}, already exists. Consider updating the term instead.")
else:
terms_dict[term_name] = [new_define]
print(f"\tTerm {term_name}, added successfully.")
return
def update_term(terms_dict):
term_name = input(f"\tPlease enter the term-name: ").strip()
if term_name in terms_dict:
new_define = input("\tPlease enter the new definition: ")
terms_dict[term_name].append(new_define)
print(f"\tDefinition added to {term_name}")
else:
print(f"\tTerm {term_name}, not found. Consider adding the term first.")
return
def get_term(terms_dict):
term_name = input(f"\tPlease enter the term-name: ")
if term_name in terms_dict:
print(f'\n\t{term_name} : {terms_dict[term_name]}')
else:
print(f"\tTerm {term_name} not found.")
return
if __name__ == '__main__':
main()