-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPlannerClassNotesTool
More file actions
36 lines (32 loc) · 1.31 KB
/
Copy pathPlannerClassNotesTool
File metadata and controls
36 lines (32 loc) · 1.31 KB
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
class Planner(object):
def __init__(self):
self.filename = 'notes.txt'
def read_notes(self):
with open(self.filename, 'r') as file:
notes = file.read()
return notes
def write_note(self, text):
with open(self.filename, 'a') as file:
file.write(text + '\n')
def generate_prompt(self, user_input):
if "read your notes" in user_input:
notes = self.read_notes()
prompt = f"Here are your notes:\n{notes}\n{user_input}"
elif "write this as a note:" in user_input:
note_text = user_input.split(":")[1].strip()
self.write_note(note_text)
prompt = f"Note saved: {note_text}"
else:
prompt = user_input
return prompt
def write_to_notes(self, prompt):
if "write this to your notes" in prompt:
try:
# Open the file in append mode
with open(self.filename, 'a') as f:
# Extract the text to write from the prompt
note_text = prompt.split("write this to your notes")[-1].strip()
f.write(note_text + "\n") # Add a newline character for better formatting
print("Note successfully written to notes.txt")
except Exception as e:
print("Error writing to notes file:", e)