kiwiz / gkeepapi

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

How to print all notes in each label? #150

Closed ooker777 closed 1 year ago

ooker777 commented 1 year ago

Here is the code:

labels = keep.labels()
for label in labels:
    print(label, label.id)
    for gnote in gnotes:
        print(gnote.title)
        print(gnote.labels.get(label.id))

The result:

☑️ Số liệu, hợp đồng 15ef2e80cb8.86b61c6386c788545
[Every note is in here] 
📝 App & service comparison 15f39a27bf5.93b4200f62f12fb7
☑️ Infographic 1643a7ff92c.a45c813dce17fd72   
☑️ Form tag.2gdou7b47cus.1557406490831        
☑️ To do, to get ready or prepared tag.2wb7naii7igs.1538994745841
📝 Untold/to say tag.gr1ls8ak15m1.1546175841091
📝 Posts tag.kep6msrj1kd1.1536654000642       
☑️ Interpersonal tag.pjqhdcsfms9v.15501388043446

To zoom in the [Every note is in here] part:

If, however, the code is:

for label in labels:
    print(label, label.id)
    for gnote in gnotes:
        if gnote.labels.get('15ef2e80cb8.86b61c6386c788545') != None: # ID of the first label
            print(gnote.title)
            print(label.id)

Then it doesn't print any note, as if the condition clause always returns false.

Why does that happen?

I use Windows 11 and Python 3.11.3.

kiwiz commented 1 year ago

The label handling logic is a bit hacky. You might have better luck with calling gnote.labels.all() to get all labels on the note.

ooker777 commented 1 year ago

man, why didn't you write it in the doc?

Anyway, I still wonder why the above code doesn't work?