]> pere.pagekite.me Git - homepage.git/blob - linux/plan2icalendar
Første utgave av scriptet for å filtrere gmane-spam.
[homepage.git] / linux / plan2icalendar
1 #!/usr/bin/perl -w
2 #
3 # Author: Petter Reinholdtsen <pere@hungry.com>
4 # Date: 2002-01-10
5 #
6 # Convert plan calender data to icalender format.
7 #
8 # plan, <URL:http://www.bitrot.de/>
9 # icalendar, RFC 2445, <URL:http://www.faqs.org/rfcs/rfc2445.html">iCalendar>
10
11 use Date::Parse;
12 use Date::Format;
13
14 my @events;
15
16 my $mailto = "pere\@hungry.com";
17
18 read_planfile(".plan.dir/dayplan");
19 write_icalendar();
20
21 sub read_planfile {
22 my ($planfile) = @_;
23 open(PLAN, "<$planfile") || die "Unable to read $planfile";
24 my $planver = <PLAN>;
25 chomp $planver;
26 while (<PLAN>) {
27 chomp;
28 if (m%\d+/\d+/\d+\s%) {
29 my ($date, $start, $duration) = split(/\s+/);
30 my $info = <PLAN>;
31 chomp $info;
32 my ($dontknow, $msg) = $info =~ m/^(.)\t(.+)$/;
33 print STDERR "E: $date $start $duration $msg\n";
34
35 my $timestamp = str2time("$date $start");
36 $isostartstamp = time2str("%Y%m%dT%H%M%S", $timestamp);
37
38 my @f = split(/:/, $duration);
39 $timestamp += ($f[0]*60*60 + $f[1]*60 +$f[2]);
40 $isoendstamp = time2str("%Y%m%dT%H%M%S", $timestamp);
41
42 print STDERR "IE: $isostartstamp $isoendstamp\n";
43 push(@events, {
44 organizer => "$mailto",
45 summary => $msg,
46 dtstart => $isostartstamp,
47 dtend => $isoendstamp,
48 priority => '1'
49 });
50 }
51 }
52 close(PLAN);
53 }
54
55
56 # BEGIN:VCALENDAR
57 # PRODID
58 # :-//K Desktop Environment//NONSGML KOrganizer//EN
59 # VERSION
60 # :2.0
61 # BEGIN:VEVENT
62 # CREATED
63 # :20020110T153939
64 # UID
65 # :KOrganizer-141229514.660
66 # SEQUENCE
67 # :0
68 # LAST-MODIFIED
69 # :20020110T153939
70 # DTSTAMP
71 # :20020110T153952
72 # ORGANIZER
73 # :MAILTO:pre@diskless.uio.no
74 # SUMMARY
75 # :SL-veiledning
76 # PRIORITY
77 # :1
78 # DTSTART
79 # :20020114T151500
80 # DTEND
81 # :20020114T160000
82 # END:VEVENT
83 # END:VCALENDAR
84 sub write_icalendar {
85 print <<EOF;
86 BEGIN:VCALENDAR
87 PRODID
88 :-//K Desktop Environment//NONSGML KOrganizer//EN
89 VERSION
90 :2.0
91 EOF
92 my $count = 0;
93 my $event;
94 for $event (@events) {
95 print <<EOF;
96 BEGIN:VEVENT
97 CREATED
98 :20020110T153939
99 UID
100 :plan2icalendar-$count
101 SEQUENCE
102 :$count
103 LAST-MODIFIED
104 :20020110T153939
105 DTSTAMP
106 :20020110T153952
107 ORGANIZER
108 :MAILTO:$event->{organizer}
109 SUMMARY
110 :$event->{summary}
111 PRIORITY
112 :$event->{priority}
113 DTSTART
114 :$event->{dtstart}
115 DTEND
116 :$event->{dtend}
117 END:VEVENT
118 EOF
119 $count++;
120 }
121 print "END:VCALENDAR\n";
122 }