Forum Archive

Reminders .save() only saves the last item in a list/dictionary as a reminder

bcohen44

I am looping thru a json object, and for each occurence of an entry that has a key of start , I want to create Reminders to a specific list (Active list in this case, could be anything, even the default). What I am finding is that it seems the r.save() is only saving the last task in the for loop below.

Any idea?

Basic code snippet

import reminders
import requests

URL = 'some URL'
headers = ' blah, blah'
req = requests.get(URL, headers=headers)
all_tasks = req.json()
all_calendars = reminders.get_all_calendars()

for calendar in all_calendars
    if calendar.title == 'Active':
        r = reminders.Reminder(calendar)

for task in all_tasks:
    if 'start' in task:
        r.title = task['description']
        r.save()
cvp

@bcohen44 I don't know anything about reminders, but could you try to move the line

r = reminders.Reminder(calendar) 

just before the line r.title = ....

Of course, you need to store your "calendar" variable

bcohen44

This worked, thanks!

cvp

@bcohen44 we are both lucky 😀