35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from copy import deepcopy
|
|
from pathlib import Path
|
|
from shutil import copy
|
|
import json
|
|
|
|
journal_path = Path.home() / '.journal.json'
|
|
|
|
copy(str(journal_path), str(journal_path.with_suffix('.bkp')))
|
|
|
|
journal = json.loads(journal_path.read_text())
|
|
new_journal = deepcopy(journal)
|
|
|
|
for day in journal['days']:
|
|
new_entries = []
|
|
for entry in journal['days'][day]['entries']:
|
|
new_blocks = []
|
|
for block in entry['blocks']:
|
|
if not isinstance(block, str) and block['type'] == 'post':
|
|
new_blocks.append({
|
|
'type': 'post',
|
|
'timestamp': block.get('timestamp', entry['timestamp'] + 30)
|
|
})
|
|
|
|
if content := block.get('content'):
|
|
new_blocks.append(content)
|
|
else:
|
|
new_blocks.append(block)
|
|
|
|
entry['blocks'] = new_blocks
|
|
new_entries.append(entry)
|
|
|
|
new_journal['days'][day]['entries'] = new_entries
|
|
|
|
journal_path.write_text(json.dumps(new_journal))
|