fetch-calendars.pl 941 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env perl
  2. use warnings;
  3. use strict;
  4. my $debug = 0;
  5. my $wget = "/usr/bin/wget";
  6. my $ical2org = "$ENV{HOME}/pipes/ical2org.pl";
  7. my $base_dir = "$ENV{HOME}/.calendars";
  8. my $org_dir = "$ENV{HOME}/Documents/org/calendars";
  9. my %calendars = (
  10. 'home' => 'https://my.owndrive.com/remote.php/caldav/calendars/PieceMaker/defaultcalendar',
  11. );
  12. chdir $base_dir;
  13. # acad and ooo don't work
  14. my @cals = qw(home);
  15. foreach my $cal (@cals) {
  16. next unless $calendars{$cal};
  17. my $cmd = "$wget -q -O $cal.ics.new $calendars{$cal} && mv $cal.ics.new $cal.ics";
  18. print STDERR "$cmd\n" if $debug;
  19. system $cmd;
  20. next unless -r "$cal.ics";
  21. $cmd = "$ical2org -c $cal < $base_dir/$cal.ics > $org_dir/$cal.org.new";
  22. print STDERR "$cmd\n" if $debug;
  23. system $cmd;
  24. if ( -s "$org_dir/$cal.org.new" ) {
  25. $cmd = "cp $org_dir/$cal.org.new $org_dir/$cal.org";
  26. print STDERR "$cmd\n" if $debug;
  27. system $cmd;
  28. }
  29. }