Ajcody-Calendar-Issues: Difference between revisions
m (Created page with '{{Unsupported}} =Calendar Issues= ==Calendar Issues Homepage== Please see Ajcody-Calendar-Issues ==Some Helpful Scripts To Run Against ICS File== ===parseics.pl === <pr…') |
(No difference)
|
Revision as of 21:44, 27 August 2010
- This article is a Community contribution and may include unsupported customizations.
Calendar Issues
Calendar Issues Homepage
Please see Ajcody-Calendar-Issues
Some Helpful Scripts To Run Against ICS File
parseics.pl
#!/usr/bin/perl $file = $ARGV[0]; if (!$file) { print "Must specify filename.\n"; exit; } elsif (!-e $file) { print "File does not exist!\n"; exit; } else { #print "File exists. Continuing...\n"; open(ICS, "<$file"); @ics = <ICS>; $errors=0; $events=0; for ($i=0;$i<=$#ics;$i++) { if ($ics[$i] =~ "BEGIN:VEVENT") { $organizer=0; $attendee=0; $event=""; #print "vevent start\n"; while ($ics[$i+1] !~ "END:VEVENT") { $event .= $ics[$i]; if ($ics[$i] =~ "ORGANIZER") { $organizer=1; } if ($ics[$i] =~ "ATTENDEE") { $attendee=1; } $i++; } #print "vevent end\n"; if ($attendee && !$organizer) { $event .= $ics[$i]; $event .= $ics[$i+1]; print "Invalid event. Attendee but no organizer present!\n"; print $event; $errors++; } $events++; } } print "$errors error(s) out of a total of $events events present.\n"; }
ical-split.pl
#!/usr/bin/perl # ical-parse.pl # b 2008 03 12 #insist on an input file if ( scalar(@ARGV) < 1 ) { print "Please specify a filename.\n" and usage() and exit; } my $infile = shift @ARGV; $numevents = qx/grep BEGIN:VEVENT $infile | wc -l/; chomp $numevents; $numevents =~ s/[^0-9]//g; $TRUE=1;$FALSE=0; $eventcount=0; $summary=''; $inVEVENT = $FALSE; # track whether we are in the middle of a vevent @currentVEVENT=(''); # hold the lines of the current vevent in this array (this will hog memory :() open( INFILE, $infile ) or die "Could not open $infile for read: $!"; while ($line = <INFILE> ) { chomp $line; if ( $line =~ m/^BEGIN:VEVENT$/ ) { # case I. ($inVEVENT) and die "Error: found new BEGIN:VEVENT without END:VEVENT\n"; $inVEVENT = $TRUE; $eventcount++; @currentVEVENT=($line); } elsif ( $line =~ m/^END:VEVENT$/ ) { # case II. (!$inVEVENT) and die "Error: found END:VEVENT without BEGIN:VEVENT\n"; push(@currentVEVENT, $line); $size = $#currentVEVENT; $zeros = zeropad($eventcount, $numevents); #eh ever heard of sprintf $outfile = "${zeros}${eventcount}-${summary}-${size}.ics"; open( OUTFILE, ">>", $outfile ) or die "Could not open $outfile for write: $!"; foreach $l (@currentVEVENT) { print OUTFILE "$l\n"; } close OUTFILE; $inVEVENT=$FALSE; $summary=''; $size=0; @currentVEVENT=(''); } elsif ( ($temp) = ( $line =~ m/^SUMMARY:(.*)$/ ) ) { # case III.A. $summary = $temp; #forget why temp $summary =~ s/[^-a-zA-Z0-9.]/_/g; push(@currentVEVENT, $line); } elsif ($inVEVENT) { # case III. push(@currentVEVENT, $line); } } $cases=' I. BEGIN:VEVENT A. (inVEVENT) and error: previous event not closed B. (else) set inVEVENT, start array, push line II. END:VEVENT A. (inVEVENT) push line, write array, unset inVEVENT, unset summary, empty array B. (else) error: no event started III. <event line> A (matches ^SUMMARY:) and set summary, push line IV. <non event line> '; exit; sub usage { print "Usage: $0 <ical file>\nWrites a new file for each VEVENT\n"; } sub zeropad() { #num-to-pad, total-with-max-digits, return 0... $num=shift; $total=shift; $curr=length($num); $max=length($total); $pad=''; for ($x=0; $x < ($max-$curr); $x++) { $pad .= '0'; } return "$pad"; }