Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty key value #15

Open
acepelon opened this issue Dec 30, 2022 · 4 comments
Open

empty key value #15

acepelon opened this issue Dec 30, 2022 · 4 comments

Comments

@acepelon
Copy link

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 #13 as well.

Thanks!
ACE

@selimrbd
Copy link
Owner

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

@acepelon
Copy link
Author

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

@selimrbd
Copy link
Owner

selimrbd commented Jan 1, 2023

If you update pyomd to the latest version (>= 0.7) this should be solved. Otherwise you can do:

for note in notes.notes:
    ...

@acepelon
Copy link
Author

acepelon commented Jan 1, 2023

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 <[email protected]>
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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants