kiwiz / gkeepapi

An unofficial client for the Google Keep API.
MIT License
1.54k stars 114 forks source link

How to retrieve all the labels from GKeep #111

Closed MagTun closed 3 years ago

MagTun commented 3 years ago

I would like to retrieve the names of all the labels in my Gkeep.

I am using labels = keep.labels() but then I am unable to extract the name from it.

I tried labels.keys(), labels.values(), labels.get(), labels.getattribute() but each time I get 'dict_values' object has no attribute .... From the doc , I see that labels return List[gkeepapi.node.Label] but if I do labels[0] I get 'dict_values' object is not subscriptable

My Gkeep has labels and if I print labels I get dict_values([<gkeepapi.node.Label object at 0x0000016149827AC0>, <gkeepapi.node.Label object at 0x0000016149834F40>])

Thanks a lot for your help!

Additionally, please provide the following information:

bew commented 3 years ago

try to do list(labels) to get a list instead of an iterator! An alternative is to navigate on it with a for, and get what you want from each label.

To get all the label names, you could do:

label_names = [label.name for label in keep.labels()]

Or without using that 'scary' one-line syntax, the manual way is:

label_names = []
for label in keep.labels():
  label_names.append(label.name)
MagTun commented 3 years ago

Thanks so much for this detailed answer @bew! Thanks to you I was able to set up my script to manage my GKeep routine. Thanks!