use strict; use warnings;
use Win32::Guidgen;
my $guid0; my $path = GetSetting("path"); my $vcalName = GetSetting("VcalName"); my $temp_years = GetSetting("years");
print "path = $path\n"; print "vcalName = $vcalName\n"; print "temp_years = $temp_years\n";
my @arrYears = split(/,/,$temp_years);
my @startTime; my @endTime;
my $i = 0; my $greenTime; GenVcalHead($path); foreach my $year (@arrYears) { for($i = 0; $i < 365; $i++) { $greenTime = GenGreenTime(); $guid0 = GetGuid(); @startTime = GenStartTime($year); @endTime = GenEndTime($year); GenVcalBody($path); } } GenVcalEnd($path);
sub GenVcalHead { my $filename = shift; open (FH,">$filename") || die "can not open $filename"; print FH <<EOF; BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Microsoft Corporation//Windows Calendar 1.0//EN CALSCALE:GREGORIAN METHOD:PUBLISH BEGIN:VTIMEZONE TZID:Beijing\, Chongqing\, Hong Kong\, Urumqi BEGIN:STANDARD DTSTART:20000101T000000 TZNAME:China Standard Time TZOFFSETFROM:+0900 TZOFFSETTO:+0800 END:STANDARD END:VTIMEZONE EOF close FH || die "can not close"; }
sub GenVcalBody { my $filename = shift; open (FH,">>$filename") || die "can not open $filename"; print FH <<EOF; BEGIN:VEVENT DESCRIPTION:aaaaaaaaaaaaa\\n\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\\n\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@ \@\@\@\@\@\@\@\\n\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\\n\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
\$\$\$\$\$\$\$\$\$\$\\n\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n\&\&\&\&\& \&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\& DTSTAMP:$greenTime DTSTART;TZID="Beijing, Chongqing, Hong Kong, Urumqi":$startTime[$i] DTEND;TZID="Beijing, Chongqing, Hong Kong, Urumqi":$endTime[$i] LOCATION:aaaaaaaaaaaaa\\n\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\\n\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@ \@\@\@\@\@\@\@\\n\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\\n\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
\$\$\$\$\$\$\$\$\$\$\\n\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n\&\&\&\&\& \&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\&\& SUMMARY:$vcalName$i UID:$guid0 END:VEVENT EOF close FH || die "can not close"; }
sub GenVcalEnd { my $filename = shift; open (FH,">>$filename") || die "can not open $filename";
print FH <<EOF; END:VCALENDAR
EOF
close FH || die "can not close"; }
sub GetGuid { my $tmpGuid = Win32::Guidgen::create(); if ($tmpGuid =~ /{(.*)}/) { $tmpGuid = $1; } return $tmpGuid; }
sub GenCurrentTime { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime; $year = $year + 1900; $mon = $mon + 1; my $currentTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",$year,$mon,$mday,$hour,$min,$sec); return $currentTime; }
sub GenGreenTime { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime; $year = $year + 1900; $mon = $mon + 1; my $greenTime = sprintf("%04d%02d%02dT%02d:%02d:%02d",$year,$mon,$mday,$hour,$min,$sec); return $greenTime; }
sub GenStartTime { my $year = shift; my @startTime; my @monDay = (31,28,31,30,31,30,31,31,30,31,30,31); my $day = 0; for (my $j = 0; $j < 12; $j++) { for (my $i = 0; $i < $monDay[$j]; $i++) { $startTime[$day++] = sprintf("%04d%02d%02dT010000",$year,$j+1,$i+1); } } return @startTime; }
sub GenEndTime { my $year = shift; my @endTime; my @monDay = (31,28,31,30,31,30,31,31,30,31,30,31); my $day = 0; for (my $j = 0; $j < 12; $j++) { for (my $i = 0; $i < $monDay[$j]; $i++) { $endTime[$day++] = sprintf("%04d%02d%02dT100000",$year,$j+1,$i+1); } } return @endTime; }
sub GetSetting { my $Item = shift; open IN, "vcal_config.txt"; my @contents = <IN>; close IN; my $path; my $vcalname; my $myyear; foreach my $line (@contents) { #print "line $line \n";
if ($line =~ /<VcalName>(.*)/i) { $vcalname = $1; } elsif ($line =~ /<Years>(.*)/i) { $myyear = $1; } elsif ($line =~ /<Path>(.*)/i) { $path = $1; } } if ($Item =~ /VcalName/i) { return $vcalname; } elsif ($Item =~ /years/i) { return $myyear; } elsif ($Item =~ /path/i) { return $path; } else { return 0; } }
|