entry modules refactor

This commit is contained in:
olari
2021-06-27 15:18:48 +03:00
parent 760d072982
commit 954e0c12af
2 changed files with 138 additions and 143 deletions

View File

@@ -0,0 +1,34 @@
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))