Skip to content

Instantly share code, notes, and snippets.

@marcus-crane
Last active April 30, 2025 23:41
Show Gist options
  • Save marcus-crane/c9e62c4832540da09d11230c90715313 to your computer and use it in GitHub Desktop.
Save marcus-crane/c9e62c4832540da09d11230c90715313 to your computer and use it in GitHub Desktop.
A small Python script to convert Diarium JSON export to the format I use in Obsidian
# Prereqs: pip install pendulum markdownify
import json
from string import Template
from markdownify import markdownify as md
import pendulum
with open("diary.json", "r") as file:
data = json.loads(file.read())
for entry in data:
date = pendulum.parse(entry.get('date'))
location = entry.get('location', False)
content = md(entry.get('html'))
template = """# $date
<< [[Private/Journal/$prevdate|$prevdate]] | [[Private/Journal/$nextdate|$nextdate]] >>
$content#journal"""
header = """---
journal: diary
journal-start-date: $date
journal-end-date: $date
journal-section: day
"""
# I use MapView so retained location
if location:
header += f"""location: [$xloc,$yloc]
"""
header += """---
"""
template = header + template
opts = {
'content': content,
'date': date.format("YYYY-MM-DD"),
'prevdate': date.add(days=-1).format("YYYY-MM-DD"),
'nextdate': date.add(days=1).format("YYYY-MM-DD")
}
if location:
opts['xloc'] = location[0]
opts['yloc'] = location[1]
src = Template(template)
result = src.substitute(opts)
with open(f'journal/{date.format("YYYY-MM-DD")}.md', 'w') as file:
file.write(result)
@marcus-crane
Copy link
Author

NOTE: I don't use this format currently but it's close enough

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