-
Notifications
You must be signed in to change notification settings - Fork 0
/
Obsidian Easy Write To Notes Remotely.py
126 lines (113 loc) · 4.6 KB
/
Obsidian Easy Write To Notes Remotely.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
#-------------Obsidian: Easy Write To Notes Remotely------------#
# Author: Adrian Papineau
# Date created: November 12th, 2021
from datetime import date
import time
import glob, os
ObsidianVaultFolder = "" # Example :"C:/Users/User/Documents/ObsidianVault/VaultName"
DailyNotesFolder = "" # Example :"C:/Users/User/Documents/ObsidianVault/VaultName/DailyNotes"
print(DailyNotesFolder)
today = date.today()
#return current daily note file path
def CurrentDate():
dateExtractMonth = today.strftime('%B')
dateExtractDay = today.strftime('%d')
dateExtractYear = today.strftime('%Y')
# Get rid of the beginning 0 in day of the month.
if dateExtractDay[0] == "0":
dateExtractDay = dateExtractDay[-1]
# Add the "th" or similar
if ((int(dateExtractDay) >= 10) and (int(dateExtractDay) <20)) or (dateExtractDay[-1] == "0") or ((int(dateExtractDay[-1]) >=4) and (int(dateExtractDay[-1]) <10)):
dateExtractNUM = str(dateExtractDay + "th")
elif dateExtractDay[-1] == "1":
dateExtractNUM = str(dateExtractDay + "st")
elif dateExtractDay[-1] == "2":
dateExtractNUM = str(dateExtractDay + "nd")
elif dateExtractDay[-1] == "3":
dateExtractNUM = str(dateExtractDay + "rd")
RoamFormat = str(dateExtractMonth + " " + dateExtractNUM + ", " + dateExtractYear)
return RoamFormat
print(CurrentDate())
def CurrentDailyNote():
DailyNoteName = (CurrentDate() + ".md")
DailyNotePath = DailyNotesFolder + "/" + DailyNoteName
return DailyNotePath
print(CurrentDailyNote())
# search the daily note
def FindLinkContent():
try:
searchfile = open(CurrentDailyNote(), "r", encoding="utf8")
EntireFile = searchfile.read()
searchfile.close()
if ">[[" in EntireFile:
indexStart = (EntireFile.index(">[["))
#print(indexStart)
everythingAfter = EntireFile[indexStart:]
#print(everythingAfter)
if "]]" in everythingAfter:
RelIndexClosing = everythingAfter.index("]]")
indexClosing = indexStart +RelIndexClosing
LinkContent = EntireFile[(indexStart+3):indexClosing]
if "[[" in LinkContent:
print("another link")
else:
return(LinkContent)
except ValueError:
print('ERROR FindLinkContent()')
def RemoveAlias():
RawLinkName = str(FindLinkContent())
if "|" in RawLinkName:
BaseName = RawLinkName.split('|')[0]
return(BaseName)
else:
return(RawLinkName)
def RemoveSymbol():
try:
searchfile = open(CurrentDailyNote(), "r", encoding="utf8")
EntireFile = searchfile.read()
searchfile.close()
if ">[[" in EntireFile:
searchfile = open(CurrentDailyNote(), encoding="utf8")
SearchContent = searchfile.read()
searchfile.seek(0)
searchfile = open(CurrentDailyNote(), "w", encoding="utf8")
FixedFile = EntireFile.replace(">[[","[[")
searchfile.write(FixedFile)
searchfile.seek(0)
searchfile.close()
except ValueError:
print('ERROR RemoveSymbol()')
# Return the path of the note that is linked
def NotePath():
LinkName = (RemoveAlias() + ".md")
LinkNotePath = ObsidianVaultFolder + "/" + LinkName
return(LinkNotePath)
def Block():
searchfile = open(CurrentDailyNote(), "r", encoding="utf8")
EntireFile = searchfile.read()
indexStart = (EntireFile.index(">[["))
everythingBefore = EntireFile[:indexStart]
RelIndexBullet = everythingBefore[::-1].index("\n")
#RelIndexBullet = everythingBefore[::-1].index("- ")
indexBullet = indexStart - RelIndexBullet
BlockContent = EntireFile[(indexBullet+1):indexStart]
return(BlockContent)
searchfile.close()
# Paste the block from daily notes into the linked note
def AppendToNote(desiredBlock):
Notefile = open(NotePath(), encoding="utf8")
NoteContent = Notefile.read()
Notefile.seek(0)
Notefile = open(NotePath(), "w", encoding="utf8")
Notefile.write(NoteContent + "\n" + "-" + desiredBlock + "[[" + CurrentDate() + "]]")
Notefile.seek(0)
Notefile.close()
while True:
if FindLinkContent() != None:
os.chdir(ObsidianVaultFolder)
for file in glob.glob(RemoveAlias() + ".md"):
print(FindLinkContent())
time.sleep(1)
AppendToNote(Block())
RemoveSymbol()
time.sleep(1)