-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataConstructor.py
378 lines (337 loc) · 11.4 KB
/
DataConstructor.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
import csv
import calendar
import os
from datetime import date
data = [""] * 23
"""
amountOfAlarms = 4 #0-3
amountOfNotifications = 12 #4-15
amountOfReportTimes = 5 #16-20
amountOfBedTimeAlert = 1 #21
"""
year = ""
displayData = []
def main():
choice = actionPrompt()
settings = getSettings()
global year
year = settings["year"]
runActionsFromChoice(choice)
def runActionsFromChoice(choice):
if(choice == 1):
month = getMonth()
day = getDay(month)
readCSVDataFromFile(month, day, 0, 3)
alarms(month, day)
elif(choice == 2):
month = getMonth()
day = getDay(month)
readCSVDataFromFile(month, day, 4, 15)
notifications(month, day)
elif(choice == 3):
month = getMonth()
day = getDay(month)
readCSVDataFromFile(month, day, 4, 15)
reportTime(month, day)
elif(choice == 4):
testData = readInTests()
displayTests(testData)
testData = editTestInfo(testData)
writeTestInformation(testData)
elif(choice == 5):
assignmentData = readInAssignment()
displayAssignment(assignmentData)
assignmentData = editAssignmentInfo(assignmentData)
writeAssignmentInformation(assignmentData)
elif(choice == 6):
runCompletionMarker()
elif(choice == 7):
runChangeDefaults()
elif(choice == 8):
changeSettings()
def changeSettings():
global year
print("What would you like to change: \n1. Change Year")
choice = input("I would like to: ")
if(choice == 1):
year = raw_input("What is the year you would like to cange to?\n Enter in the year: ")
choice = input("Do you want to make this permenant\n1. NO\t RECCOMENDED\n2. Yes\t[would be best to use if it is a new year]\n\nI would like to: ")
if(choice == 2):
infile = open("settings.txt", "w")
infile.write("year=" + year +"\n")
infile.close()
choice = actionPrompt()
runActionsFromChoice(choice)
def runCompletionMarker():
import completed
def runChangeDefaults():
import changeDefaults
def readInAssignment():
assignmentData = []
infile = open("assignments.csv")
line = infile.readline().strip()
count = 0
while(count != 10):
if(line != ","):
date, assignmentInfo = line.split(",")
assignmentData.append(date + ": " + assignmentInfo)
else:
assignmentData.append(" ")
count += 1
line = infile.readline().strip()
infile.close()
return assignmentData
def displayAssignment(assignmentData):
print("DATE: Description")
count = 1
for i in range(0, 10):
info = assignmentData[i]
print(str(count) + ".) " + info)
count += 1
def editAssignmentInfo(assignmentData):
choice = input("What would you like to change: ")
month = raw_input("what is the month that it is due: ")
day = raw_input("what is the day that it is due: ")
assignmentInfo = (raw_input("Please give a descrition or title for the assignment: "))
assignmentData[int(choice) - 1] = (month + "-" + day + ": " + assignmentInfo)
return assignmentData
def writeAssignmentInformation(assignmentData):
infile = open("assignments.csv", "w")
text = ""
for i in range(0, 10):
info = assignmentData[i]
if(info != " "):
date, assignmentInfo = info.split(": ")
text = text + date+ "," + assignmentInfo + "\n"
else:
text = text + ",\n"
infile.write(text)
infile.close()
def readInTests():
testData = []
infile = open("tests.csv")
line = infile.readline().strip()
count = 0
while(count != 10):
if(line != ","):
date, testInfo = line.split(",")
testData.append(date + ": " + testInfo)
else:
testData.append(" ")
count += 1
line = infile.readline().strip()
infile.close()
return testData
def displayTests(testData):
print("DATE: Description")
count = 1
for i in range(0, 10):
info = testData[i]
print(str(count) + ".) " + info)
count += 1
def editTestInfo(testData):
choice = input("What would you like to change: ")
month = raw_input("what is the month that it is due: ")
day = raw_input("what is the day that it is due: ")
testInfo = (raw_input("Please give a descrition or title for the test: "))
testData[int(choice) - 1] = (month + "-" + day + ": " + testInfo)
return testData
def writeTestInformation(testData):
infile = open("tests.csv", "w")
text = ""
for i in range(0, 10):
info = testData[i]
if(info != " "):
date, testInfo = info.split(": ")
text = text + date+ "," + testInfo + "\n"
else:
text = text + ",\n"
infile.write(text)
infile.close()
def displayDataValues():
global displayData
number = 1
for i in displayData:
print(str(number) + ": " + i)
number += 1
def readCSVDataFromFile(month, day, low, high):
dayCounter = 1
collection = []
infile = open(year + "-" + str(month) +".csv")
line = infile.readline().strip()
while(len(line)>0):
if(dayCounter == day):
loadIntoStorage(line, low, high)
dayCounter = dayCounter + 1
line = infile.readline().strip()
infile.close()
def loadIntoStorage(dataCollection, low, high):
valuesHolder = []
valuesHolder = dataCollection.split(',')
getDisplayData(valuesHolder, low, high)
def getDisplayData(valuesHolder, low, high):
global displayData
for i in range(low, high+1):
displayData.append(valuesHolder[i])
print(displayData)
def reportTime(month, day):
print("The current notification times are: ")
displayDataValues()
choice = input("Enter number of what you would like to modify: ")
editTimes(choice)
dataToBeWritten = buildWriteData(16, 20, month, day)
writeData(dataToBeWritten, month)
def notifications(month, day):
print("The current notifications that are assigned are: ")
displayDataValues()
choice = input("Enter number of what you would like to modify: ")
editText(choice)
dataToBeWritten = buildWriteData(4, 15, month, day)
writeData(dataToBeWritten, month)
def alarms(month, day):
print("The current alarms are: ")
displayDataValues()
choice = input("Enter number of what you would like to modify: ")
editTimes(choice)
dataToBeWritten = buildWriteData(0, 3, month, day)
writeData(dataToBeWritten, month)
def writeData(dataToBeWritten, month):
infile = open(year + "-" + str(month) +".csv", "w")
infile.write(dataToBeWritten)
infile.close()
def buildWriteData(low, high, month, day):
global displayData
dayCounter = 1
valuesHolder = []
dataToBeWritten = ""
modifiedData = ""
infile = open(year + "-" + str(month) +".csv")
line = infile.readline().strip()
while(len(line)>0):
if(dayCounter == day):
valuesHolder = line.split(',')
for i in range(low, high+1):
valuesHolder[i] = displayData[i - low]
for i in range(0,22):
if(i != 0):
modifiedData += ","
modifiedData = modifiedData + valuesHolder[i]
dataToBeWritten = dataToBeWritten + modifiedData + "\n"
else:
dataToBeWritten = dataToBeWritten + line + "\n"
dayCounter = dayCounter + 1
line = infile.readline().strip()
print dataToBeWritten
infile.close()
return dataToBeWritten
def editText(i):
global displayData
text = raw_input("What would you like to be reminded about: ")
displayData[i-1] = text
def editTimes(i):
global displayData
hour = raw_input("hour of alarm: ")
minute = raw_input("Minute of alarm: ")
time = (str(hour) + ":" + str(minute))
displayData[i-1] = time
def actionPrompt():
print("WELCOME TYLER!\n1. alarms\n2. notification")
print("3. Report Times\n4. Set test info\n5. set assignment info\n6. Set task as completed\n7. Set Defualt times\n8. settings")
choice = input("What would like to do: ")
print(50 * "\n")
return choice
def getMonth():
print("1: JAN\t2: FEB\n3: MAR\t4: APR\n5: MAY\t6: JUN\n7: JUL\t8: AUG")
print("9: SEP\t10: OCT\n11: NOV\t12: DEC")
month = input("Which month: ")
doesFileExist(month)
return month
def doesFileExist(month):
filesInExistance = []
state = False
infile = open("filesConstructed.txt")
line = infile.readline()
while len(line) > 0:
filesInExistance.append(line)
line = infile.readline()
infile.close()
fileSize = len(filesInExistance)
for i in filesInExistance:
if( i == ("2016-" + str(month) + ".csv")):
state = True
if (state != True):
createFile(month)
makeNoteThatFileExist(month)
def makeNoteThatFileExist(month):
file = open("filesConstructed.txt", "a")
file.write(str(year) + "-" + str(month) + ".csv\n")
file.close()
def createFile(month):
global year
c = (open(str(year) + "-" + str(month) + ".csv", "w"))
c.close()
default = getDefaultValues()
writeStartData(default, month)
def getDefaultValues():
default = {}
infile = open("defaultValues.txt")
line = infile.readline().strip()
while(len(line)>0):
weekDay, listOfValues = line.split("=")
valuesHolder = listOfValues.split(',')
line = infile.readline().strip()
default[weekDay] = valuesHolder
infile.close()
return default
def writeStartData(default, month):
file = open(str(year) + "-" + str(month) + ".csv", "a")
monthLength = getMonthLength(month)
for dateNum in range(0, monthLength):
weekday = getWeekday(dateNum, month)
section = default[weekday]
completeSection = ""
for i in range(0, 21):
if(i == 0):
completeSection = completeSection + section[0]
elif(i == 16):
completeSection = completeSection + section[2]
elif(i == 17):
completeSection = completeSection + section[3]
completeSection = completeSection + ","
completeSection = completeSection + section[1]
file.write(completeSection + "\n")
def getMonthLength(month):
ml = calendar.monthrange(2016, month)
monthLength = ml[1]
return monthLength
def getDay(month):
monthLength = getMonthLength(month)
print("possible values are 1 - " + str(monthLength))
day = input("what day would you like to access: ")
day = checkIfDayIsValid(month, day, monthLength)
return day
def checkIfDayIsValid(month, day, monthLength):
if( 0 < day <= monthLength):
return day
else:
print("day choosen is invalid")
day = getDay(month)
return day
def getWeekday(dateNum, month):
global year
weekDaysList = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
dateNum = dateNum + 1
dateInput = [year, month, dateNum]
dayOfTheWeek = date(int(year), month, dateNum).weekday()
return weekDaysList[dayOfTheWeek]
def getSettings():
infile = open("settings.txt")
line = infile.readline().strip()
settings = {}
while(len(line)>0):
valueName, value = line.split("=")
settings[valueName] = value
line = infile.readline().strip()
infile.close()
return settings
main()