This repository has been archived by the owner on Nov 20, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
138 lines (115 loc) · 4.35 KB
/
main.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from clint.textui import puts, indent
from app.Calendar import Calendar
from pyfiglet import Figlet
from models.event import Event
import datetime
import sys
from util.util import bcolors
class Main(object):
def __init__(self):
self.calender = Calendar()
def print_usage(self):
puts(bcolors.OKGREEN)
f = Figlet(font='slant')
puts(f.renderText('Calender App'))
puts(bcolors.ENDC)
def print_event_item(self, event):
with indent(8):
puts(event.event_name)
with indent(4):
puts("=> " + event.event_description)
puts("-" * 60)
def print_day_events(self, events):
with indent(4):
puts("Date: " + events[0].event_date)
for event in events:
self.print_event_item(event)
def parse_date(self):
event_date = None
while True:
puts(bcolors.BOLD)
event_date = raw_input("Date [YYYY-MM-DD]: ").strip()
if event_date == "":
puts(bcolors.UNDERLINE + bcolors.WARNING +
"The Date is empty" +
bcolors.ENDC)
continue
try:
datetime.datetime.strptime(event_date, '%Y-%m-%d')
break
except ValueError:
puts(bcolors.UNDERLINE + bcolors.WARNING +
"Incorrect date format, should be YYYY-MM-DD" +
bcolors.ENDC)
continue
puts(bcolors.ENDC)
return event_date
def create_event(self):
print ('Add New Calendar Item')
with indent(4):
event_date = self.parse_date()
event_name = None
while True:
event_name = raw_input("Event Title: ")
if event_name == "":
continue
else:
break
event_description = None
while True:
event_description = raw_input("Event Description: ")
if event_description == "":
continue
else:
break
event = Event(event_date, event_name, event_description)
return event
def run_app(self):
self.print_usage()
while True:
with indent(4):
puts(bcolors.BOLD)
puts("MENU")
puts(bcolors.ENDC)
with indent(4):
puts('1. Add new Event to calender')
puts('2. List Events by date')
puts('3. Get Latest Event')
puts('4. Exit')
puts("\n")
action = None
while True:
try:
puts(bcolors.BOLD)
action = raw_input("select action to continue: ")
action = int(action.strip())
puts(bcolors.ENDC)
if action in [1, 2, 3, 4]:
break
except ValueError:
print (bcolors.UNDERLINE + bcolors.WARNING +
"Error: Invalid Menu item" +
bcolors.ENDC)
puts("=" * 80)
if action == 1:
event = self.create_event()
self.calender.add_new_event(event)
elif action == 2:
date = self.parse_date()
data = self.calender.search_event(date)
if data is not None:
self.print_day_events(data)
else:
with indent(4):
puts("Date: " + date)
puts("No items scheduled for Date")
elif action == 3:
latest_event = self.calender.get_last_item()
self.print_day_events([latest_event])
elif action == 4:
with indent(4):
puts('Good Bye')
sys.exit(0)
print ("=" * 80)
main = Main()
main.run_app()