-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
194 lines (153 loc) · 5.92 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# main.py
#/usr/bin/python3
import sys
import argparse
import datetime
import jsonpickle
import os
#from pathlib import Path
class StatusReport():
def __init__(self):
self.monday_date : datetime
self.messages = [ "", "", "", "", ""]
self.next_week_goal = ""
self.need_help = ""
def overwrite(self, day) -> bool:
n : str = ""
if self.messages[day] != "":
n = input("Already filled: " + self.messages[day] + "\nErase? (y/n)")
else: return True
n = n.lower().strip()
if n == "y" or n == "yes":
return True
return False
def setMondayDate(self, date) -> None:
self.monday_date = date
def recordMessage(self, day):
assert(day < 8 and day > -1)
if self.overwrite(day):
self.messages[day] = input("enter reflection: ")
else:
return
def recordMessage(self, day, message = "") -> None:
assert(day < 8 and day > -1)
print (message)
if self.overwrite(day):
if message != "":
self.messages[day] = message
else:
self.messages[day] = input("enter reflection: ")
print("message written" + message)
else:
print("message not written")
return
def isFinished(self) -> bool:
return self.next_week_goal != "" and self.need_help != ""
def setNextWeekGoal(self) -> None:
n : str = ""
if self.next_week_goal != "":
n = input("Already filled! Erase? (y/n)")
if n == "y" or n == "Y" or n == "":
self.next_week_goal = input("enter next step: ")
else:
return
def setNeedHelp(self) -> None:
n : str = ""
if self.need_help != "":
n = input("Already filled! Erase need help? (y/n)")
if n == "y" or n == "Y" or n == "":
self.need_help = input("enter need help: ")
else:
return
def generate(self) -> str:
return """Launchie Weekly Report
Name: Eric Sims
Date of Monday: """ + self.monday_date.strftime("%d %B %Y") + """
What I've learned from specific activities and accomplishments throughout the week
Monday: """ + self.messages[0] + """
Tuesday: """ + self.messages[1] + """
Wednesday: """ + self.messages[2] + """
Thursday: """ + self.messages[3] + """
Friday: """ + self.messages[4] + """
Planned accomplishments for next week: """ + self.next_week_goal + """
Requested assistance: """ + self.need_help
# Command line arguments
arg_parser = argparse.ArgumentParser(description="Filling out the Weekly Status Report")
arg_parser.add_argument("-m", "--message", type=str, help="Reflect on the day")
arg_parser.add_argument("-e", "--email", action= 'store_true', help="Email to supervisor")
arg_parser.add_argument("-g", "--goal", help="Goal for next week")
arg_parser.add_argument("-n", "--need", help="Requesting help")
arg_parser.add_argument("-d", "--display", action= 'store_true', help="Display report")
group = arg_parser.add_mutually_exclusive_group()
group.add_argument("-v", "--verbose", action="store_true")
group.add_argument("-q", "--quiet", action="store_true")
args = arg_parser.parse_args()
def prompt():
print( """************** Launchie Report Filler ****************
w - Reflections for today's work
p - Reflections for another weekday
f - Finish the document
e - Email report to supervisor
h - help
q - quit (auto saves)
******************************************************""")
verbose : bool = args.verbose
quiet : bool = args.quiet
cmd : str = ""
currentDate = datetime.datetime.now()
weekday = currentDate.weekday()
mondayDate = datetime.datetime.now() - datetime.timedelta(days=currentDate.weekday())
filePathJSON = "data/report_" + mondayDate.strftime("%m_%d_%Y") + ".json"
filePathTXT = "reports/report_" + mondayDate.strftime("%m_%d_%Y") + ".txt"
print("filePath: " + filePathJSON) if verbose else None
# Check if report is already created
if (os.path.isfile(filePathJSON)):
with open(filePathJSON, "r") as f:
report = jsonpickle.decode(f.read())
else:
# no previous report made, make a new one
report = StatusReport()
report.setMondayDate(mondayDate)
if args.message != None:
report.recordMessage(weekday, str(args.message))
print("Recorded message for " + currentDate.strftime("%A"))
elif args.display:
print(report.generate())
elif args.goal != None:
report.nextweek_goal = args.goal
print("Set next week goal: " + report.next_week_goal) if verbose else None
elif args.need != None:
report.need_help = args.need
print("Set need help: " + report.need_help) if verbose else None
else:
# INPUT EVENT LOOP
prompt() if not quiet else None
while (1):
cmd = input(">>> ")
if cmd == 'q': break
elif cmd == 'w':
print ("response for today") if verbose else None
report.recordMessage(weekday)
print(report.messages) if verbose else None
elif cmd == 'p':
print("response for previous days") if verbose else None
custom_day = int(input("0 - Monday\t1 - Tuesday\t2 - Wednesday\t3 - Thursday\t4 - Friday\nday: "))
report.recordMessage(custom_day)
print(report.messages) if verbose else None
elif cmd == 'e':
print("emailing supervisor") if verbose else None
txt = report.generate()
with open(filePathTXT, "w") as f:
f.write(txt)
elif cmd == 'f':
print("finishing documentation") if verbose else None
report.setNextWeekGoal()
report.setNeedHelp()
elif cmd == 'h' or cmd == 'help':
prompt()
else:
print("Invalid command")
# Save report
frozen = jsonpickle.encode(report)
with open(filePathJSON, "w") as f:
f.write(frozen)