How to remove all events from the Google calendar from the specified date?

I use googlecalendar plugin to work with google calendar with ruby.

The only problem I encountered is removing the event from the Google calendar.

I found an example to remove an event in the above github. But we need to pass the event identifier. How can I use the code below to remove all events from the Google calendar from a specified date?

CODE:

require File.dirname(__FILE__) + '/../shared.rb' g = GData.new puts 'login' token = g.login(' REPLACE_WITH_YOUR_MAIL@gmail.com ', 'REPLACE_WITH_YOUR_PASSWORD') puts "token: #{token}" event = {:title=>'title', :content=>'content', :author=>'pub.cog', :email=>' pub.cog@gmail.com ', :where=>'Toulouse,France', :startTime=>'2009-06-20T15:00:00.000Z', :endTime=>'2009-06-20T17:00:00.000Z'} create_response = g.new_event(event) puts create_response.body puts 'delete_event' # TODO GET id from new_event response id='http://www.google.com/calendar/feeds/default/private/full/pgvgjdnh43g3bo0emnpfg0gnr4' response = g.delete_event(id) puts 'done' 

URL:

https://github.com/francisoud/googlecalendar/blob/master/googlecalendar/examples/ruby_standalone/gdata_delete_event.rb

Share your thoughts if we can do this with other plugins.

Thanks in Advance :)

+4
source share
1 answer

A search on github led to this gogle , which seems to be a more popular stone (if not standard). It is also better documented and organized.

Here is what I came up with:

 require 'google_calendar' cal = Google::Calendar.new(:username => ' username@gmail.com ', :password => 'password', :app_name => 'delete_events') cal.events.each { |event| event.delete if Time.parse(event.start_time) >= Time.new(2011,10,14) } 

Time.parse sets the start time of each event in a format that ruby ​​can understand, and then compares it with the specified date on October 14, 2011. If the event is enabled or after the event, it is deleted. To delete events, follow these steps:

  if Time.parse(event.start_time) <= Time.new(2011,10,14) 

or for all events on a specific date, do:

  if Time.parse(event.start_time) == Time.new(2011,10,14) 
+2
source

Source: https://habr.com/ru/post/1483781/


All Articles