-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork_log_wDB.py
89 lines (76 loc) · 2.45 KB
/
work_log_wDB.py
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
"""
Python Web Development Techdegree
Project 4 - Work Log with a Database
--------------------------------
Developed by: Ayman Said
Mar-2019
"""
import os
from collections import OrderedDict
import util
def initialize():
"""Create the database and the table if they don't exist."""
util.db.connect()
util.db.create_tables([util.Entry], safe=True)
def main_menu():
"""The startup program screen, the user is presented with
the initial user options:
add a new entry, search for entries or quit.
:return: None
"""
menu_title = "What would you like to do?"
welcome_msg = "Data Based Work Log"
# An OrderedDict representing the main menu items & their functions
menu = OrderedDict([
('a', util.add_entry),
('s', search_entries),
('q', quit_program),
])
choice = None
while choice != 'q':
# clear the screen
os.system("cls" if os.name == "nt" else "clear")
print("-" * len(welcome_msg))
print(welcome_msg)
print("-" * len(welcome_msg))
print(menu_title)
for key, value in menu.items():
# using the function docstring as the menu items
print('{}) {}'.format(key, value.__doc__))
choice = input('Action: ').lower().strip()
if choice in menu:
menu[choice]()
else:
input("Invalid selection!!!, press Enter to try again...")
continue
def search_entries():
"""Search for entries"""
menu_title = "Please select your desirable search method:"
search_menu = OrderedDict([
('e', util.find_employee),
('d', util.find_date),
('r', util.find_dates_range),
('t', util.find_time_spent),
('p', util.find_phrase),
('q', util.quit_menu),
])
choice = None
while choice != 'q':
# clear the screen
os.system("cls" if os.name == "nt" else "clear")
print(menu_title)
for key, value in search_menu.items():
# using the function docstring as the menu items
print('{}) {}'.format(key, value.__doc__))
choice = input('Action: ').lower().strip()
if choice in search_menu:
search_menu[choice]()
else:
input("Invalid selection!!!, press Enter to try again...")
continue
def quit_program():
"""Quit the program"""
print("Quitting...Hope to see you soon!")
if __name__ == '__main__':
initialize()
main_menu()