-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
56 lines (44 loc) · 2.47 KB
/
__main__.py
File metadata and controls
56 lines (44 loc) · 2.47 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
import json
import os
from CodingChallengeModule.Classes import Employee, Manager
from CodingChallengeModule.DataReader import DataReader
from CodingChallengeModule.JsonDataReader import JsonDataReader
from CodingChallengeModule.EmployeeHierarchyPrinter import EmployeeHierarchyPrinter
from CodingChallengeModule.SortedEmployeeHierarchyPrinter import SortedEmployeeHierarchyPrinter
from CodingChallengeModule.SalaryRequirementPrinter import SalaryRequirementPrinter
# Main
if __name__ == "__main__":
# Load app settings from settings file
with open('appsettings.json', 'r') as settingsFile:
settings = json.load(settingsFile)
# Guard clause to check for an empty 'settings' variable
if settings == None:
raise TypeError('ERROR :: Problem reading "appsettings.json"!')
if type(settings['EmployeeHierarchyFileName']) != str:
raise TypeError('ERROR :: Value for settings parameter "EmployeeHierarchyFileName" must be a string!')
if type(settings['SortEmployeeHierarchyOutput']) != bool:
raise TypeError('ERROR :: Value for settings parameter "SortEmployeeHierarchyOutput" must be a bool!')
# Get the app settings values for the specified keys
employeeHierarchyFileName = settings['EmployeeHierarchyFileName']
sortEmployeeHierarchyOutputFlag = settings['SortEmployeeHierarchyOutput']
# Create the filepath to the employee hierarchy json file
hierarchyFilePath = os.path.join(os.getcwd(), employeeHierarchyFileName)
# Create a DataReader object
dataReader = JsonDataReader(hierarchyFilePath)
# Create the data printers that deal with the formatting of the output
# if 'SortEmployeeHierarchyOutput' is true, create a SortedEmployeeHierarchyPrinter:
if sortEmployeeHierarchyOutputFlag:
hierarchyPrinter = SortedEmployeeHierarchyPrinter()
# else, create an unsorted EmployeeHieararchyPrinter
else:
hierarchyPrinter = EmployeeHierarchyPrinter()
# Create a salary requirement printer
salaryRequirementPrinter = SalaryRequirementPrinter()
# Read Employee Data from Data Source
rootManager = dataReader.Read()
# Call the data printers' 'PrintString' methods to get the formatted output strings
employeeHierarchyString = hierarchyPrinter.PrintString(rootManager)
salaryRequirementString = salaryRequirementPrinter.PrintString(rootManager)
# Print each formatted output string
print(employeeHierarchyString)
print(salaryRequirementString)