-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtvcalendar2csv.pl
More file actions
47 lines (35 loc) · 929 Bytes
/
tvcalendar2csv.pl
File metadata and controls
47 lines (35 loc) · 929 Bytes
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
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use Data::ICal;
my $calendar_url = "http://www.pogdesign.co.uk/cat/download_ics/2af7747583b17bb008bf5c5211305089";
my %shows = ();
my $ua = LWP::UserAgent->new();
my $ical = $ua->get($calendar_url)->content;
my $entries = Data::ICal->new(data => $ical)->entries;
for my $entry (@{$entries}){
my %properties = %{$entry->properties()};
my $value = $properties{'categories'}[0]->value;
$value = sanitize($value);
$shows{$value} = '720p';
}
# input CSV file overides online calendar
while(<>){
chomp;
(my $name, my $quality) = split(/;/,$_);
$shows{$name} = $quality;
}
for my $k (keys %shows){
print "$k;$shows{$k};\n";
}
sub sanitize {
my $name = shift;
$name =~ s/\s*(.+)\s+Episodes, TV Shows/$1/;
$name =~ s/\://g;
$name =~ s/\bThe\b//gi;
$name =~ s/^\s+//g;
$name =~ s/\s+$//g;
$name =~ s/[[:punct:]]//g;
return $name;
}