-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (26 loc) · 924 Bytes
/
main.py
File metadata and controls
37 lines (26 loc) · 924 Bytes
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
import json
from input_module import get_employee_details
def read_json_file(file_path):
try:
with open(file_path, 'r') as f:
employee_list = json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError):
employee_list = []
return employee_list
def write_json_to_file(json_obj, output_file):
with open(output_file, 'w') as f:
json.dump(json_obj, f, indent=4)
def main():
file_path = './employees.json'
employee_list = read_json_file(file_path)
while True:
employee_dict = get_employee_details()
employee_list.append(employee_dict)
print('\n')
choice = input(
"Do you want to enter details for another employee? (Y/N): ")
if choice.lower() == 'n':
break
write_json_to_file(employee_list, file_path)
if __name__ == '__main__':
main()