Mercurial > hg > Applications > Calcon
comparison 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 |
comparison
equal
deleted
inserted
replaced
24:888b08634e8f | 25:98d017d452c6 |
---|---|
4376 sub name { | 4376 sub name { |
4377 my ($self,$record,@names)=@_; | 4377 my ($self,$record,@names)=@_; |
4378 $record->{'name'} = "@names"; | 4378 $record->{'name'} = "@names"; |
4379 } | 4379 } |
4380 | 4380 |
4381 #######################################################################/ | |
4382 | |
4383 package Calcon::iApps_read; | |
4384 | |
4385 # iCal から sqlite3 経由で読み込む。、 | |
4386 | |
4387 use strict; | |
4388 # use warnings; | |
4389 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | |
4390 use NKF; | |
4391 use DBI; | |
4392 use File::Path qw(make_path); | |
4393 use Time::Local; | |
4394 | |
4395 @ISA = ( 'Calcon::File_read' ) ; | |
4396 | |
4397 sub initialize { | |
4398 my ($self) = @_; | |
4399 $self->SUPER::initialize(); | |
4400 $self->{'-labels'} = \%record_keys; | |
4401 # print STDERR "option ",join(" ", keys %$self), "\n"; | |
4402 } | |
4403 | |
4404 sub decode { | |
4405 my ($self,$file) = @_; | |
4406 my ($debug) = $self->{'-debug'}; | |
4407 my $out = $self->{'-output'}; | |
4408 my $record; | |
4409 my $keys; | |
4410 if (! $file) { # we need sanitize | |
4411 $file = "new"; | |
4412 } | |
4413 $self->{-file} = $file; | |
4414 | |
4415 $out->start_file(''); | |
4416 $self->get_all_event() if (! $self->{'-address-only'}); | |
4417 $out->end_file(''); | |
4418 } | |
4419 | |
4420 sub date { | |
4421 my ($self,$mac) = @_; | |
4422 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mac+978274800); | |
4423 $year += 1900; | |
4424 $mon += 1; | |
4425 return $self->make_date("$year/$mon/$mday $hour:$min"); | |
4426 } | |
4427 | |
4428 sub get_all_event { | |
4429 my ($self) = @_; | |
4430 my $CalDB = $ENV{'HOME'}."/Library/Calendars/Calendar.sqlitedb"; | |
4431 my $mdb = DBI->connect("dbi:SQLite:dbname=$CalDB","",""); | |
4432 my $sql = $mdb->prepare('select start_date,end_date,summary,description from CalendarItem,Calendar where calendar_id = Calendar.ROWID and Calendar.title = "'. $self->{-file}. '"'); | |
4433 $sql->execute or die("db error $sql->errstr"); | |
4434 my $today = $self->today(); | |
4435 my ($year,$mon,$mday,$hour,$min) = $today->localtime(); | |
4436 my $keys = []; | |
4437 while (my $cal = $sql->fetchrow_hashref ) { | |
4438 if (defined $cal->{'start_date'}) { | |
4439 my $record = $self->make_record; | |
4440 $record->{'date'} = $self->date($cal->{'start_date'}) ; | |
4441 # $record->show; | |
4442 return if ($self->{'-future-only'} && ! $record->{'date'}->future()); | |
4443 return if ($self->{'-tomorrow'} && ! $record->{'date'}->tomorrow()); | |
4444 # return if ($self->{'-count'} == 0); | |
4445 $record->{'end-date'} = $self->date($cal->{'end_date'}) ; | |
4446 $record->{'summary'} = $cal->{'summary'} ; | |
4447 $record->{'memo'} = $cal->{'description'} ; | |
4448 push(@$keys,keys %{$record}); | |
4449 my $out = $self->{'-output'}; | |
4450 $out->record($keys,$record); | |
4451 } | |
4452 } | |
4453 } | |
4454 | |
4455 | |
4456 | |
4381 1; | 4457 1; |
4382 | 4458 |
4383 __END__ | 4459 __END__ |
4384 | 4460 |
4385 =cut | 4461 =cut |