|
Revision 285, 1.8 kB
(checked in by miya, 2 years ago)
|
import Net::Google::Calendar
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
use Data::Dumper; |
|---|
| 5 |
use Net::Google::Calendar; |
|---|
| 6 |
use Data::ICal::Entry::Event; |
|---|
| 7 |
use Date::ICal; |
|---|
| 8 |
|
|---|
| 9 |
my $url = shift || die "You must pass a feed url\n"; |
|---|
| 10 |
|
|---|
| 11 |
my $cal = Net::Google::Calendar->new( url => $url ); |
|---|
| 12 |
|
|---|
| 13 |
my $u = shift; |
|---|
| 14 |
my $p = shift; |
|---|
| 15 |
|
|---|
| 16 |
$cal->login($u, $p); |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
if (!@ARGV) { |
|---|
| 20 |
for ($cal->get_events()) { |
|---|
| 21 |
print Dumper $_->as_xml; |
|---|
| 22 |
next; |
|---|
| 23 |
print $_->title."\n"; |
|---|
| 24 |
print $_->id."\n"; |
|---|
| 25 |
print $_->content->body."\n*****\n\n"; |
|---|
| 26 |
} |
|---|
| 27 |
exit; |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
my $title = shift; |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
my $entry = Net::Google::Calendar::Entry->new(); |
|---|
| 35 |
$entry->title($title); |
|---|
| 36 |
$entry->content("My content"); |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$entry->when(DateTime->now, DateTime->now() + DateTime::Duration->new( hours => 6 ) ); |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
my $recurrence = Data::ICal::Entry::Event->new(); |
|---|
| 48 |
|
|---|
| 49 |
use DateTime::Event::Recurrence; |
|---|
| 50 |
use Date::ICal; |
|---|
| 51 |
use DateTime::Format::ICal; |
|---|
| 52 |
|
|---|
| 53 |
my $last_day_of_the_month = DateTime::Event::Recurrence->monthly( days => -1 ); |
|---|
| 54 |
$recurrence->add_properties( |
|---|
| 55 |
dtstart => DateTime::Format::ICal->format_datetime(DateTime->now), |
|---|
| 56 |
rrule => DateTime::Format::ICal->format_recurrence($last_day_of_the_month), |
|---|
| 57 |
); |
|---|
| 58 |
|
|---|
| 59 |
$entry->recurrence($recurrence); |
|---|
| 60 |
|
|---|
| 61 |
print STDERR $entry->as_xml."\n\n\n*********************\n\n"; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
my $tmp = $cal->add_entry($entry); |
|---|
| 65 |
die "Couldn't add event: $@\n" unless defined $tmp; |
|---|
| 66 |
|
|---|
| 67 |
print "Events=".scalar($cal->get_events())."\n"; |
|---|
| 68 |
|
|---|
| 69 |
die $tmp->as_xml; |
|---|
| 70 |
|
|---|
| 71 |
$tmp->content('Updated'); |
|---|
| 72 |
|
|---|
| 73 |
print "Update\n"; |
|---|
| 74 |
$cal->update_entry($tmp) || die "Couldn't update ".$tmp->id.": $@\n"; |
|---|
| 75 |
|
|---|
| 76 |
print "Delete\n"; |
|---|
| 77 |
|
|---|
| 78 |
|
|---|