-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemoryLoader.py
42 lines (32 loc) · 1.18 KB
/
memoryLoader.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
from Utilities import dataManipulation as dataUtils
from Utilities import dateUtils
import os.path
preferences = {}
# adds the days of the week to a file
def create_new_lunch_memory():
with open('lunchMemory.txt', 'w') as f:
f.write("Monday=\n")
f.write("Tuesday=\n")
f.write("Wednesday=\n")
f.write("Thursday=\n")
f.write("Friday=\n")
def get_previous_lunches():
if dateUtils.check_new_week():
create_new_lunch_memory()
elif not os.path.isfile('lunchMemory.txt') or os.path.getsize('lunchMemory.txt') <= 0:
create_new_lunch_memory()
with open('lunchMemory.txt', 'r') as f:
for line in f:
line_array = dataUtils.remove_linefeed(line).split("=")
if '=' in line:
preferences[line_array[0]] = line_array[1]
return preferences
# add a lunch to the file for today's day of the week
def add_lunch(place, past_lunches):
day = dateUtils.get_day_of_week()
with open('lunchMemory.txt', 'w') as f:
for (k, v) in past_lunches.items():
if day == k:
f.write("%s=%s\n" % (day, place))
else:
f.write("%s=%s\n" % (k, v))