Created
May 9, 2014 05:14
-
-
Save yoshinari-nomura/644e632515a8eb046819 to your computer and use it in GitHub Desktop.
Remove all calendar evens from Google calendar using mhc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Usage: caldav-delete-all <calendarname> | |
# | |
# <calendarname>: calendar name found in ~/.mhc/config.yml | |
if File.symlink?(__FILE__) and ENV["RBENV_VERSION"] | |
ENV["RBENV_VERSION"] = nil | |
shims_path = File.expand_path("shims", ENV["RBENV_ROOT"]) | |
ENV["PATH"] = shims_path + ":" + ENV["PATH"] | |
exec(File.readlink(__FILE__), *ARGV) | |
end | |
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__) | |
require 'rubygems' | |
require 'bundler/setup' | |
require "mhc" | |
Encoding.default_external="UTF-8" | |
conf_file = "~/.mhc/config.yml" | |
calname = ARGV.shift | |
config = Mhc::Config::Sync.create_from_yaml_file(conf_file) | |
builder = Mhc::Builder.new(config) | |
begin | |
caldav = builder.calendar(calname) | |
rescue StandardError => e | |
STDERR.print "Error: " + e.message.capitalize + "\n" | |
exit 1 | |
end | |
STDERR.print "Delete all articles in #{calname}...\n" | |
caldav.report_etags.each do |uid, etag| | |
STDERR.print "deleting #{uid}\n" | |
caldav.delete(uid) | |
end | |
STDERR.print "Done.\n" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment