-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchronicler.py
48 lines (35 loc) · 1.02 KB
/
chronicler.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
# food chronicler aka diet journal
import datetime
class Journal:
def __init__(self, filename):
self.today = datetime.date.today()
if filename != "":
self.filename = filename
else:
# default to today's date
self.filename = str(today) + ".txt"
self.entries = []
def add_entry(self, entry):
self.entries.append(entry)
def save(self):
with open(self.filename, "w") as f:
for entry in self.entries:
f.write(entry + "\n")
def load(self):
with open(self.filename, "r") as f:
for line in f:
self.entries.append(line.rstrip())
def print_entries(self):
for entry in self.entries:
print(entry)
def main():
# Create a new journal
journal = Journal()
# Add some entries
journal.add_entry("First entry.")
journal.add_entry("Second entry.")
# Save the journal
journal.save()
# Print the entries
journal.print_entries()
main()