Status
Done
% completed
Start date
End date
Duration
Hours estimated
0
Hours spent
0
Spent time diff
Spent time % change
Cost
Description
Results
Doc 2 notion flow
- I add a line of text in any doc synced with my one drive
- I run the script manually
- saves the date/time when started to run in a variable
runStartTimestamp
- get last time the script started to run
-
const lastRunTimestamp = ./lastRunTimestamp.txt
- gets the files names in the folders to be scanned
- list of folders to be scanned will be a hardcoded array in V1
- Save the remaining file names as objects in the file_path array item as
[{
"file_path": "<file_path>",
"files": []
}]
[{
"file_path": "<file_path>",
"files": [{
"name": "<file_name>",
"todos": []
}]
}]
- get stats for every file name in the list and save in the obj as:
[{
"file_path": "<file_path>",
"files": [{
"name": "<file_name>",
"last_modified": yyyy-MM-dd'T'HH:mm:ss.SSSZ
"todos": []
}]
}]
- filter file names that have
end with .docx
andstat.mtime > lastTimeScriptRan
- for each file name resulting from the filter
- get the the
word/comments.xml
content and saves in a variablecommentsContent
- unzips the .docx file to a local directory
./tmp
using bash commandunzip
- reads the content of the
word/comments.xml
file usingfs.readFileSync
- extract the TODOs with pattern below from file content
TODO <task name> by <due date YYYY-MM-dd> [(tracked)]
- Convert todo strings to list of objs by parsing fields from string
- filter untracked todos where
track_status = false
- for each untracked todo in the list
- create task in notion
- Use the logic in this tutorial https://developers.notion.com/docs/create-a-notion-integration
- POC code implemented in
notion_poc.js
- field mapping
- desc > name of the DB item
- due date > Date prioritized
- file_name > Src file name
- file_path > Src file path
- if success
- update text in the note to indicate with
(tracked)
to indicate that the todo has been tracked - update in
commentsContent
with the content ofcomments.xml
using a regex to identify the text of the original todo and replace with: text + ' (tracked)'
- update
note.track_status = true
- if fail
- update
note.error_msg = <error message>
- Append list of untracked todos (that now might be tracked) objs to corresponding file obj in
file.todos
as - update the content of
word/comments.xml
file in./tmp
with the value ofcommentsContent
usingfs.writeFileSync
- Zip the contents of
./tmp
in a.docx
file with the same name as the original file and write it in the original path in the OneDrive folder - saves execution report
- saves in local file in
./.logs/<lastTimeScriptRan>.txt
withlastTimeScriptRan
in same format as 2023-07-25T23:18:07.000Z and in UTC - Execution report should be the final json used through the execution generated by JSON.stringify(report, null, 2)
- saves
runStartTimestamp
value in./lastTimeScriptRan.txt
[{
"original_text": "TODO <task name> by <due date YYYY-MM-dd> [(tracked)]",
"desc": "<task name>",
"due_date": "YYYY-MM-dd",
"track_status": false | true
"error_msg": ""
}]
[{
"file_path": "<file_path>",
"files": [{
"name": "<file_name>",
"last_modify_dt": yyyy-MM-dd'T'HH:mm:ss.SSSZ
"todos": [{
"original_text": "TODO <task name> by <due date YYYY-MM-dd> [(tracked)]",
"desc": "<task name>",
"due_date": "YYYY-MM-dd",
"track_status": false
"error_msg": ""
}]
}]
}]
[{
"file_path": "<file_path>",
"files": [{
"name": "<file_name>",
"todos": [{
"desc": "<task name>",
"due_date": "YYYY-MM-dd",
"track_status": false
"error_msg": ""
}]
}]
}]
Insights
- Had to change the approach from using the content of the document.xml to comments.xml instead because content in document.xml was weird sometimes. Ex: TODO create script by Jul 26 would appear as below
- I thought this was hard to predict and the contents of the comments seemed more standardized
<w:p w14:paraId="1921F443" w14:textId="1511460D" w:rsidR="00015415"
w:rsidRDefault="00015415" w:rsidP="00015415">
<w:pPr>
<w:pStyle w:val="ListParagraph" />
<w:numPr>
<w:ilvl w:val="0" />
<w:numId w:val="2" />
</w:numPr>
</w:pPr>
<w:commentRangeStart w:id="0" />
<w:r w:rsidRPr="00937622">
<w:t xml:space="preserve">TODO create </w:t>
</w:r>
<w:r w:rsidR="00937622" w:rsidRPr="00937622">
<w:t>script by Jul 2</w:t>
</w:r>
<w:r w:rsidR="00937622">
<w:t>6</w:t>
</w:r>
<w:commentRangeEnd w:id="0" />
<w:r w:rsidR="00416F57">
<w:rPr>
<w:rStyle w:val="CommentReference" />
</w:rPr>
<w:commentReference w:id="0" />
</w:r>
</w:p>
- Note for future versions, by using the comments it’s possible to mark the comment as “resolved” by changing the prop done of the commentsExtended.xml file like below. This will not be implemented in V1, but seems like a nice feature for the Notion to doc flow:
<w15:commentEx w15:paraId="58C6F26B" w15:done="1" />
- When I have the doc open in my desktop and the script runs updating a comment, the content of the doc is not updated automatically. If I close the doc and reopen without changing anything, the comment appears updated.
- If I update the doc after it was updated by the script and save it, than the script changes are overwritten. If I then close and reopen the doc, my changes are there, but the script changes are not
Notion to doc flow
TODO in next version