# HG changeset patch # User Shinji KONO # Date 1676770561 -32400 # Node ID 98d017d452c69fea46dd0b64b6309127c4c4ed06 # Parent 888b08634e8f93cebe9dddfb19447d36f04993d6 add sqlite3 based iCal diff -r 888b08634e8f -r 98d017d452c6 Calcon.pm --- a/Calcon.pm Sun Feb 19 08:46:59 2023 +0900 +++ b/Calcon.pm Sun Feb 19 10:36:01 2023 +0900 @@ -4378,6 +4378,82 @@ $record->{'name'} = "@names"; } +#######################################################################/ + +package Calcon::iApps_read; + +# iCal から sqlite3 経由で読み込む。、 + +use strict; +# use warnings; +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); +use NKF; +use DBI; +use File::Path qw(make_path); +use Time::Local; + +@ISA = ( 'Calcon::File_read' ) ; + +sub initialize { + my ($self) = @_; + $self->SUPER::initialize(); + $self->{'-labels'} = \%record_keys; + # print STDERR "option ",join(" ", keys %$self), "\n"; +} + +sub decode { + my ($self,$file) = @_; + my ($debug) = $self->{'-debug'}; + my $out = $self->{'-output'}; + my $record; + my $keys; + if (! $file) { # we need sanitize + $file = "new"; + } + $self->{-file} = $file; + + $out->start_file(''); + $self->get_all_event() if (! $self->{'-address-only'}); + $out->end_file(''); +} + +sub date { + my ($self,$mac) = @_; + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mac+978274800); + $year += 1900; + $mon += 1; + return $self->make_date("$year/$mon/$mday $hour:$min"); +} + +sub get_all_event { + my ($self) = @_; + my $CalDB = $ENV{'HOME'}."/Library/Calendars/Calendar.sqlitedb"; + my $mdb = DBI->connect("dbi:SQLite:dbname=$CalDB","",""); + my $sql = $mdb->prepare('select start_date,end_date,summary,description from CalendarItem,Calendar where calendar_id = Calendar.ROWID and Calendar.title = "'. $self->{-file}. '"'); + $sql->execute or die("db error $sql->errstr"); + my $today = $self->today(); + my ($year,$mon,$mday,$hour,$min) = $today->localtime(); + my $keys = []; + while (my $cal = $sql->fetchrow_hashref ) { + if (defined $cal->{'start_date'}) { + my $record = $self->make_record; + $record->{'date'} = $self->date($cal->{'start_date'}) ; + # $record->show; + return if ($self->{'-future-only'} && ! $record->{'date'}->future()); + return if ($self->{'-tomorrow'} && ! $record->{'date'}->tomorrow()); + # return if ($self->{'-count'} == 0); + $record->{'end-date'} = $self->date($cal->{'end_date'}) ; + $record->{'summary'} = $cal->{'summary'} ; + $record->{'memo'} = $cal->{'description'} ; + push(@$keys,keys %{$record}); + my $out = $self->{'-output'}; + $out->record($keys,$record); + } + } +} + + + 1; __END__ diff -r 888b08634e8f -r 98d017d452c6 calcon.pl --- a/calcon.pl Sun Feb 19 08:46:59 2023 +0900 +++ b/calcon.pl Sun Feb 19 10:36:01 2023 +0900 @@ -14,6 +14,7 @@ 'Vcard' => 'Calcon::Vcard_read', 'SLA300' => 'Calcon::Sla300_read', 'iApp' => 'Calcon::iApp_read', + 'iCal' => 'Calcon::iApps_read', 'Entourage' => 'Calcon::Entourage_read', 'File' => 'Calcon::File_read', ); diff -r 888b08634e8f -r 98d017d452c6 pool.pl --- a/pool.pl Sun Feb 19 08:46:59 2023 +0900 +++ b/pool.pl Sun Feb 19 10:36:01 2023 +0900 @@ -13,6 +13,7 @@ 'Vcard' => 'Calcon::Vcard_read', 'SLA300' => 'Calcon::Sla300_read', 'iApp' => 'Calcon::iApp_read', + 'iCal' => 'Calcon::iApps_read', 'Entourage' => 'Calcon::Entourage_read', 'File' => 'Calcon::File_read', );