Mercurial > hg > Applications > Calcon
diff Calcon.pm @ 25:98d017d452c6 default tip
add sqlite3 based iCal
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 19 Feb 2023 10:36:01 +0900 |
parents | 888b08634e8f |
children |
line wrap: on
line diff
--- 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__