Skip to content

Instantly share code, notes, and snippets.

@m000
Created April 29, 2020 11:05
Show Gist options
  • Save m000/d32f28ded1f19115e950c988b776a8d5 to your computer and use it in GitHub Desktop.
Save m000/d32f28ded1f19115e950c988b776a8d5 to your computer and use it in GitHub Desktop.
Export all your Laverna notes as markdown
#!/usr/bin/env python3
from pathlib import Path
import json
import os
if __name__ == '__main__':
root = Path('.')
notes = (root / 'notes').glob('*.json')
export = root / 'export'
export.mkdir(exist_ok=True)
for nf in notes:
note = json.loads(nf.read_text())
notemd = None; notemd_idx = 0
while notemd is None or notemd.exists():
if notemd is None:
notemd = export / ('%s.md' % (note['title']))
else:
notemd = export / ('%s_%02d.md' % (note['title'], notemd_idx))
notemd_idx += 1
notemd.write_text(note['content'])
ts = (note['updated']/1000,)*2
os.utime(notemd, ts)
@m000
Copy link
Author

m000 commented Apr 29, 2020

I had been using Laverna for a while. I had a few dozens of notes taken, but in the end I didn't stick with it. Cleaning up my Dropbox folder (where Laverna syncs), I found my old notes. I wrote this small script to export them to Markdown before cleaning up the folder. The script needs to be run inside the Laverna Dropbox app folder. I didn't care to preserve the notebook hierarchy, so the script doesn't process the contents of the notebooks folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment