Changeset 447
- Timestamp:
- 10/16/07 17:33:37 (11 months ago)
- Files:
-
- cybozu2ical/trunk/cybozu2ical (modified) (2 diffs)
- cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cybozu2ical/trunk/cybozu2ical
r446 r447 88 88 'compat-google-calendar', 89 89 'debug', 90 'input-csv=s', 91 'output-csv=s', 90 92 'help', 91 93 ) or pod2usage(2); … … 108 110 # Obtain Cybozu Office 6 Calendar items 109 111 my $cal = WWW::CybozuOffice6::Calendar->new(%$cfg); 112 113 if ($opt{'input-csv'}) { 114 $cal->read_from_csv_file($opt{'input-csv'}) 115 or die "Failed to read CSV file: $opt{'input-csv'}"; 116 } else { 117 $cal->request() 118 or die "Failed to get Cybozu Office 6 Calendar"; 119 } 120 121 # Output the calendar CSV for debugging 122 if ($opt{'output-csv'}) { 123 local *FH; 124 open FH, ">$opt{'output-csv'}" or die "Failed to write $opt{'output-csv'}"; 125 print FH "$_\n" for $cal->response; 126 close FH; 127 } 110 128 111 129 # For each items, generate an 'event entry' and append it to the calendar cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar.pm
r446 r447 35 35 } 36 36 37 sub get_items { 38 my $this = shift; 39 40 my $res = $this->_request(); 37 sub request { 38 my $this = shift; 39 40 my $res = $this->{ua}->post($this->{url} . '?page=SyncCalendar', { 41 _System => 'login', 42 _Login => 1, 43 csv => 1, 44 notimecard => 1, 45 defined $this->{username} ? (_Account => $this->{username}) : (), 46 defined $this->{userid} ? (_Id => $this->{userid} ) : (), 47 Password => $this->{password} || '', 48 }); 41 49 die 'Failed to access Cybozu Office 6: ' . $res->status_line 42 50 unless $res->is_success; … … 45 53 from_to($content, $this->{input_encoding} || 'shiftjis', 'utf8'); 46 54 my @lines = grep /^\d+,ts\.\d+,/, split(/\r?\n/, $content); 55 $this->{response} = \@lines; 56 57 scalar @lines ? \@lines : undef; 58 } 59 60 sub read_from_csv_file { 61 my $this = shift; 62 my ($file) = @_; 63 local *FH; 64 open FH, $file or die "Failed to read $file"; 65 my @lines; 66 while (<FH>) { 67 chomp; push @lines, $_; 68 } 69 close(FH); 70 $this->{response} = \@lines; 71 72 scalar @lines ? \@lines : undef; 73 } 74 75 sub response { 76 my $res = $_[0]->{response} || {}; 77 wantarray ? @$res : $res; 78 } 79 80 sub get_items { 81 my $this = shift; 47 82 48 83 my @items; 49 84 my $csv = Text::CSV_XS->new({ binary => 1 }); 50 for my $line ( @lines) {85 for my $line ($this->response) { 51 86 $csv->parse($line) 52 87 or die 'Failed to parse CSV input'; … … 103 138 } 104 139 105 sub _request {106 my $this = shift;107 $this->{ua}->post($this->{url} . '?page=SyncCalendar', {108 _System => 'login',109 _Login => 1,110 csv => 1,111 notimecard => 1,112 defined $this->{username} ? (_Account => $this->{username}) : (),113 defined $this->{userid} ? (_Id => $this->{userid} ) : (),114 Password => $this->{password} || '',115 });116 }117 118 140 package WWW::CybozuOffice6::Calendar::Event; 119 141 … … 268 290 ); 269 291 292 # request calendar contents 293 $calendar->request(); 294 270 295 # get list of items in the calendar 271 296 my @items = $calendar->get_items(); … … 346 371 Gets/sets the Cybozu Office 6 encoding. 347 372 373 =item request() 374 375 Requests to obtain the contents of Cybozu Office 6 Calendar. 376 377 =item read_from_csv_file($filename) 378 379 Instead of requesting Cybozu Office 6 server, reads from a local CSV file. 380 348 381 =item get_items() 349 382
