forked from talonhub/community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.py
78 lines (65 loc) · 2.58 KB
/
random.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
from datetime import datetime
import os
from pathlib import Path
import subprocess
from talon import Module, actions
NOTES_DIR = Path(__file__).parent / "notes"
NOTES_DIR.mkdir(exist_ok=True)
mod = Module()
@mod.action_class
class Actions:
def create_note():
"""Create a new note"""
curtime = datetime.now().strftime("%Y-%m-%d-%H%M%S")
file_path = NOTES_DIR / f"{curtime}.md"
print(f"Creating note at {file_path}")
file_path.touch()
actions.sleep("500ms")
print(f"Opening note at {file_path}")
os.startfile(file_path, "open")
def edit_note(file_name: str):
"""Edit an existing note"""
file_path = NOTES_DIR / file_name
if file_path.exists():
edit_file(file_path)
else:
actions.app.notify(f"Note {file_name} does not exist.")
def append_to_daily_note_text(text: str):
"""Append provided text to daily note"""
file_path = NOTES_DIR / "daily note.md"
with open(file_path, 'a', encoding='utf-8') as f:
f.write(text + '\n')
# os.startfile(file_path, "edit")
def create_or_append_date_note_text(text: str = None):
"""Create or append provided text to date-named note"""
curdate = datetime.now().strftime("%Y-%m-%d")
file_path = NOTES_DIR / f"{curdate}.md"
if text:
with open(file_path, 'a', encoding='utf-8') as f:
f.write(text + '\n')
else:
if not file_path.exists():
file_path.touch()
# edit_file(file_path)
def add_note_to_physical_therapy(text: str):
"""Add a new note to the top of the physical therapy document"""
file_path = Path(r"C:\Users\rebec\Dropbox\DropboxDocuments\notes\physical_therapy_daily.md")
current_date = datetime.now().strftime("%A, %B %d, %Y")
# Read existing content
if file_path.exists():
with open(file_path, 'r', encoding='utf-8') as f:
existing_content = f.read()
else:
existing_content = ""
# Prepare new content
new_content = f"{current_date}\n{text}\n\n{existing_content}"
# Write updated content
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"Added new note to {file_path}")
def open_file_custom(path: str):
"""Open a file"""
if actions.app.platform == "mac":
subprocess.run(["open", path])
else: # windows
os.startfile(path, "open")