Skip to content

Commit

Permalink
add example for deleting unused tags
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Feb 28, 2024
1 parent 6aab8c2 commit 931f3dd
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,30 @@ for tag in api.get_all_tags():

</details>

<details>
<summary>Remove unused tags</summary>

Reference: <https://discourse.joplinapp.org/t/prune-empty-tags-from-web-clipper/36194>

```python name=remove_unused_tags
from joppy.api import Api

# Create a new Api instance.
api = Api(token=YOUR_TOKEN)

for tag in api.get_all_tags():
notes_for_tag = api.get_all_notes(tag_id=tag.id)
if len(notes_for_tag) == 0:
print("Deleting tag:", tag.title)
api.delete_tag(tag.id)
```

</details>

<details>
<summary>Remove spaces from tags</summary>

Inspired by <https://www.reddit.com/r/joplinapp/comments/pozric/batch_remove_spaces_from_all_tags/>.
Reference: <https://www.reddit.com/r/joplinapp/comments/pozric/batch_remove_spaces_from_all_tags/>

```python name=remove_spaces_from_tags
import re
Expand Down Expand Up @@ -192,7 +212,7 @@ assert len(referenced_resources) > 0, "sanity check"

for resource in api.get_all_resources():
if resource.id not in referenced_resources:
print("Deleting resource:", resource)
print("Deleting resource:", resource.title)
api.delete_resource(resource.id)
```

Expand Down

0 comments on commit 931f3dd

Please sign in to comment.