Google Cal API Python: множественное удаление с ошибкой ExecuteBatch - PullRequest
2 голосов
/ 08 октября 2011

Я пытаюсь удалить все события календаря, используя Google API для python. Если я удаляю события одно за другим, это прекрасно работает, но это очень долго и неоптимизировано, поэтому я пытаюсь сделать то же самое, используя ExecuteBatch, который я использую для вставки большого количества записей в календарь (и это прекрасно работает перед вставкой).

def DeleteAllEntryOfCalendar(calendar_client, name_calendar):
    #Request_feed for doing the delete
    request_feed = gdata.calendar.CalendarEventFeed()
    #Get the Uri of the cal we've to delete all entries
    uri = GetUri(calendar_client, name_calendar)
    feed = calendar_client.GetAllCalendarsFeed()
    for a_cal in feed.entry:
        if a_cal.title.text == name_calendar:
            calendar = a_cal    
    #For each entry in the cal, do a delete request entry in request_feed
    query = gdata.calendar.client.CalendarEventQuery()
    query.max_results = 1000
    feed = calendar_client.GetCalendarEventFeed(uri=uri, q=query)
    for an_entry in feed.entry:
        an_entry.batch_id = gdata.BatchId(text='delete-request')
        request_feed.AddDelete(entry=an_entry)    
        entry = ''

    # submit the batch request to the server
    response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')

И я получил ошибку:

Traceback (most recent call last):
  File "c.py", line 253, in <module>
    DeleteAllEntryOfCalendar(client, name_calendar)
  File "c.py", line 187, in DeleteAllEntryOfCalendar
    response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')
  File "/usr/local/lib/python2.6/dist-packages/gdata/calendar/client.py", line 432, in     execute_batch
    return self.Post(batch_feed, url, desired_class=desired_class)
  File "/usr/local/lib/python2.6/dist-packages/gdata/client.py", line 681, in post
    entry.to_string(get_xml_version(self.api_version)),
AttributeError: 'CalendarEventFeed' object has no attribute 'to_string'

Я повторяю, что когда я делаю то же самое для вставки событий, это работает нормально. Я много искал и пробовал много возможностей, и я не могу это сделать. Если у вас есть идея ...

1 Ответ

1 голос
/ 19 января 2012

Использование

gdata.calendar.data.CalendarEventFeed

Некоторые объекты в библиотеке Python gdata имеют две версии, и вы не можете смешивать их вместе.

...