]> git.donarmstrong.com Git - bin.git/blob - debconf_pb_to_ics
add reset usb bus command
[bin.git] / debconf_pb_to_ics
1 #!/usr/bin/perl
2 # SCRIPTNAME DOES_SOMETHING
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
5 # more information.
6 # Copyright 2016 by Don Armstrong <don@donarmstrong.com>.
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 use LWP::Simple;
16 use XML::LibXML;
17 use POSIX qw(strftime);
18 use DateTime;
19 use DateTime::Format::DateParse qw(parse_datetime);
20
21 =head1 NAME
22
23 SCRIPTNAME - DOES_SOMETHING
24
25 =head1 SYNOPSIS
26
27 SCRIPTNAME [options]
28
29  Options:
30    --debug, -d debugging level (Default 0)
31    --help, -h display this help
32    --man, -m display manual
33
34 =head1 OPTIONS
35
36 =over
37
38 =item B<--debug, -d>
39
40 Debug verbosity. (Default 0)
41
42 =item B<--help, -h>
43
44 Display brief usage information.
45
46 =item B<--man, -m>
47
48 Display this manual.
49
50 =back
51
52 =head1 EXAMPLES
53
54 SCRIPTNAME
55
56 =cut
57
58
59 use vars qw($DEBUG);
60
61 my %options = (debug           => 0,
62                help            => 0,
63                man             => 0,
64               );
65
66 GetOptions(\%options,
67            'debug|d+','help|h|?','man|m');
68
69 pod2usage() if $options{help};
70 pod2usage({verbose=>2}) if $options{man};
71
72 $DEBUG = $options{debug};
73
74 my @USAGE_ERRORS;
75 # if (1) {
76 #     push @USAGE_ERRORS,"You must pass something";
77 # }
78
79 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
80
81
82 my $xml = XML::LibXML->load_xml(string => get('https://debconf16.debconf.org/schedule/pentabarf.xml'));
83
84 print << 'EOF';
85 BEGIN:VCALENDAR
86 VERSION:2.0
87 X-WR-CALNAME:pentabarf_to_ics
88 PRODID:-//PentabarfToICS//EN
89 X-WR-TIMEZONE:UTC
90 X-WR-CALDESC:Pentabarf To ICS
91 CALSCALE:GREGORIAN
92 EOF
93 my $timestamp = strftime('%Y%m%dT%H%M%SZ',gmtime);
94 for my $event ($xml->findnodes('.//event')) {
95     print STDERR $event->toString if $DEBUG;
96     my $id = $event->getAttribute('id');
97     my $start = DateTime::Format::DateParse->parse_datetime(node_content($event,'date'));
98     $start->set_time_zone('UTC');
99     my $start_stamp = strftime('%Y%m%dT%H%M%SZ',gmtime($start->epoch));
100     my $duration = node_content($event,'duration');
101     if (not defined $duration or $duration eq ':') {
102         $duration = node_content($xml,'timeslot_duration');
103     }
104     my ($h,$m) = $duration =~ /(\d+)\:(\d+)/;
105     $duration = DateTime::Duration->new(hours => $h,minutes => $m);
106     my $stop_stamp = strftime('%Y%m%dT%H%M%SZ',gmtime(($start+$duration)->epoch));
107     my $summary = node_content($event,'title');
108     my $description = node_content($event,'description');
109     $description =~ s/\n/\\n/g;
110     my $url = node_content($event,'full_conf_url');
111     my $type = node_content($event,'type');
112     print <<"EOF";
113 BEGIN:VEVENT
114 DTSTAMP:$timestamp
115 UID: $id
116 DTSTART: $start_stamp
117 DTEND: $stop_stamp
118 SUMMARY: $summary
119 DESCRIPTION:: $description
120  $url
121 CATEGORIES: $type
122 END:VEVENT
123 EOF
124 }
125
126
127 print << 'EOF';
128 END:VCALENDAR
129 EOF
130
131
132 sub node_content {
133     my ($xml,$node) = @_;
134
135     my ($n) = $xml->findnodes(".//$node");
136     return $n->textContent();
137 }
138
139 __END__