-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeHours.py
More file actions
96 lines (85 loc) · 2.86 KB
/
Copy pathEmployeeHours.py
File metadata and controls
96 lines (85 loc) · 2.86 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
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import os
import random
def initialize_firestore():
"""
Create database connection
"""
# Setup Google Cloud Key
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "cs246-db-project-firebase-adminsdk-7clw1-06397866ff.json"
# Use the application default credentials
cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred, {
'projectId': 'cs246-db-project',
})
# Get reference to database
db = firestore.client()
return db
def find_employee(db, id):
"""
Finding the employee information in the database
"""
result = db.collection("Employees").document(id).get()
if result.exists:
empInfo = result.to_dict()
return empInfo
else:
return None
def update_emp(db, id, hoursTrained, trainedStatus):
"""
Create or update an employee
"""
trainingInfo = {"Hours Trained" : hoursTrained,
"Training Completed" : trainedStatus}
db.collection("Employees").document(id).set(trainingInfo)
def delete_emp(db, id):
"""
Delete a player
"""
db.collection("Employees").document(id).delete()
def main():
db = initialize_firestore()
print()
emp_id = input("Please enter employee id: ")
quit_program = False
while not quit_program:
hours = find_employee(db, emp_id)
empHoursTrained = hours["Hours Trained"]
empCompletedTraining = hours["Training Completed"]
print()
print("Select Option:")
print("t -- Add hours trained\n"
"u -- Update training status\n"
"c -- Check hours trained\n"
"s -- Check training status\n"
"a -- Add employee\n"
"d -- Delete employee\n"
"e -- Exit\n")
option = input(">>> ")
if option == "t":
trainingHours = int(input("Hours to add: "))
trainingHours += empHoursTrained
update_emp(db, emp_id, trainingHours, empCompletedTraining)
elif option == "u":
isTrained = input("Is training complete? (y/n): ")
if isTrained == "y":
update_emp(db, emp_id, empHoursTrained, True)
else:
update_emp(db, emp_id, empHoursTrained, False)
elif option == "c":
print("Hours Trained: {}".format(empHoursTrained))
elif option == "s":
print("Training Complete? {}".format(empCompletedTraining))
elif option == "a":
newID = input("What is the new employee ID? ")
update_emp(db, newID, 0, False)
elif option == "d":
delete_emp(db, emp_id)
print("Employee {} deleted".format(emp_id))
quit_program = True
elif option == "e":
quit_program = True
if __name__ == "__main__":
main()