-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv2ical.pl
146 lines (111 loc) · 3.53 KB
/
csv2ical.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl
use strict;
use warnings;
use if -d "perl5", 'local::lib' => 'perl5';
use Getopt::Long;
use Pod::Usage;
use File::Temp qw( :POSIX );
use Tie::iCal;
use DateTime::Format::ICal;
Getopt::Long::Configure (
'auto_abbrev', # Allows truncation of options
'gnu_compat' # Allows --opt=BLA syntax and --opt "BLA"
);
my $file;
my $help = 0;
my $stdout = 0;
my $vcal = 0;
my %shows;
GetOptions (
'file=s' => \$file,
'stdout' => \$stdout,
'vcal' => \$vcal,
'help' => \$help,
) and ($file || $stdout)
or die pod2usage( # Print documentation and quit if bad opts
-exitval => $help, # With return value 0 if $help was not set
-verbose => 2 # Print all the sections
);
$file = tmpnam() if $stdout;
system "touch $file";
tie %shows, 'Tie::iCal', $file;
my %dayHash = (
'Mon' => ['MO',1],
'Tues' => ['TU',2],
'Wed' => ['WE',3],
'Thus' => ['TH',4],
'Fri' => ['FR',5],
'Sat' => ['SA',6],
'Sun' => ['SU',7],
);
<>; # Discard header
while (<>) {
chomp;
next if /^#/;
my ($slug, $name, $host, $email, $activity, $live, $start, $end, $day, $semester, $description) = split "\t";
next if $activity eq 'Inactive';
$start = [ split ':', $start ];
$end = [ split ':', $end ];
$day = $dayHash{$day};
$shows{$slug.':'.$email} = [
'VEVENT',
{
'SUMMARY' => $name,
'DESCRIPTION' => '"'.$description.' Host email '.$email.'"',
'DTSTART' => DateTime::Format::ICal->format_datetime(DateTime->new(
year => 2016,
month => 2,
day => $day->[1],
hour => $start->[0],
minute => $start->[1],
second => $start->[2],
time_zone => '-0500',
)),
'DTEND' => DateTime::Format::ICal->format_datetime(DateTime->new(
year => 2016,
month => 2,
day => $day->[1],
hour => $end->[0],
minute => $end->[1],
second => $end->[2],
time_zone => '-0500',
)),
'RRULE' => {
'FREQ' => 'WEEKLY',
# 'BYDAY' => $day->[0],
},
'REPEAT' => 15,
'ORGANIZER' => 'MAILTO:'.$email,
'ATTENDEE' => [
[{'MEMBER' => 'MAILTO'}, $email]
],
},
];
}
untie %shows;
unless ($vcal) {
my $staging = tmpnam();
system "echo BEGIN:VCALENDAR > $staging && grep -v VCALENDAR $file >> $staging && echo END:VCALENDAR >> $staging && cat $staging > $file && rm $staging";
}
system "cat $file && rm $file" if $stdout;
__END__
=head1 NAME
AO3 Downloader
=head1 SYNOPSIS
ao3-download -u UID [options]
=head1 OPTIONS
=over 12
=item B<-uid>
User ID on AO3. [required]
=item B<-processes>
Processes to run at once.
=item B<-format>
Format to download works in. Valid values are epub (default), mobi, pdf, and html.
=item B<-directory>
Where to download files (default current directory).
=item B<-section>
Section to download. Valid values are bookmarks (default), and works. (Collections and Serieses are not supported at this time).
=back
=head1 DESCRIPTION
B<This program> will download the works found for a section of a given user page.
=cut