Open acepelon opened 1 year ago
Hello @acepelon , you can use remove_empty()
(documentation link). Although this method is only accessible through the Note API, not the Notes one (yet). So you'd have to do somehting like:
for note in notes:
note.metadata.remove_empty()
Let me know if it does the job
Thank you for the quick response.
I apologize for my lack of python, but it tells me notes isn't iterable.
` [snip]
notes.write() for note in notes: note.metadata.remove_empty()`
yielded:
Traceback (most recent call last): File "/Users/acepelon/git/example-vault/test-pomd-add-remove-metadata.py", line 14, in <module> for note in notes: TypeError: 'Notes' object is not iterable
If you update pyomd to the latest version (>= 0.7) this should be solved. Otherwise you can do:
for note in notes.notes:
...
Thank you for your patience. I didn't see a recent update to py-obsidianmd in git:
example-vault>>git pull;git log
Already up to date.
commit 19e948140ff68d81312bc7dd05eb75ec53fc6a16 (HEAD -> main, origin/main, origin/HEAD)
Author: Selim Raboudi <selim.raboudi@gmail.com>
Date: Mon Nov 28 12:48:41 2022 +0100
Update README.md
and I show the latest version of py-obsidianmd as:
py-obsidianmd 0.1.7
but regardless, your advice like this works great. I appreciate it!
from pyomd import Notes
from pyomd import Note
from pyomd.metadata import MetadataType
from pathlib import Path
path = Path('~/example-vault/media')
notes = Notes(path)
for note in notes.notes:
note.metadata.remove_empty()
notes.update_content(inline_inplace=False, inline_position="top",inline_tml="callout")
notes.write()
Hi,
I apologize for my ignorance, but as I was trying this out, I discovered that when I do a remove, it removes the value but leaves the key:
notes.metadata.remove(k="tags",l="type/book",meta_type=MetadataType.INLINE)
for example leaves me with:
tags ::
I imagine I am just missing it, but I see this in the YT video as well. Is there an option to remove both key and value? I can run a sed like
sed '/:: *$/d' The\ Listening\ Book\ -\ by\ W.A.\ Mathieu.md
after the fact to remove it, but it seems like maybe removing the key if it has an empty value could be an option also? Would then potentially relate to https://github.com/selimrbd/py-obsidianmd/issues/13 as well.Thanks! ACE