Yoshinori Matsunobu: Linux Performance Tuning and Stabilization Tips
[HTML5TV.git] / bin / calendar.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use lib 'lib';
7 use HTML5TV::hCalendar;
8 use File::Slurp;
9 use XML::FeedPP;
10 use HTML::ResolveLink;
11
12 my $url = 'http://html5tv.rot13.org';
13
14 my $style = qq|
15 <style type="text/css">
16
17 |
18 . read_file('www/css/hCalendar.css')
19 . qq|
20
21 .watch {
22         margin-right: 0.1em;
23 }
24
25 </style>
26 |;
27
28 my $html = qq|<!DOCTYPE html>
29 <html>
30
31 <head>
32 <meta charset="utf-8" />
33
34 <link rel="alternate" type="application/rss+xml" title="RSS" href="calendar.xml">
35
36 <link rel="icon" type="image/png" href="media/favicon.png">
37
38 <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
39
40 <script src="js/jqueryhcal/jqueryhcal.js" type="text/javascript"></script>
41 <link rel="stylesheet" type="text/css" href="js/jqueryhcal/jqueryhcal.css" />
42
43 <link rel="stylesheet" type="text/css" href="css/hCalendar.css" />
44
45 $style
46
47 <title>HTML5TV all media available</title>
48
49 </head>
50
51 <body>
52
53 <div id="jhCalendar"></div>
54
55 |;
56
57 my $vevents;
58 my $feed = XML::FeedPP::RSS->new;
59 $feed->title( 'HTML5TV' );
60 $feed->link( $url );
61
62 my $resolver = HTML::ResolveLink->new( base => $url );
63
64 foreach my $path ( glob 'media/*/hCalendar.html' ) {
65         next if $path =~ m{_editing};
66         warn "+ $path\n";
67
68         my $hcal = HTML5TV::hCalendar->new( $path );
69
70         my $media = (split(/\//, $path))[1];
71
72         if ( ! -e "www/$media.html" ) {
73                 warn "NO www/$media.html $!";
74                 next;
75         }
76
77         my $html = $hcal->as_HTML(
78                 [ 'span', { class => 'watch' },
79                         [ 'a', { href => "$media.html", title => $media, },
80                                 [ 'img', { src => 'media/favicon.png', border => 0 } ],
81                         ]
82                 ]
83         );
84
85         $vevents->{ $hcal->dtstart_iso . $media } = $html;
86
87         my $pubDate = $hcal->dtstart_iso;
88         $pubDate =~ s{^(\d\d\d\d)(\d\d)(\d\d).*$}{$1-$2-$3};
89
90         my $item = $feed->add_item( "$url/$media.html" );
91         $item->title( $hcal->summary );
92         $item->pubDate( $pubDate );
93         $item->description( $resolver->resolve( $html ) );
94 }
95
96 $feed->to_file( 'www/calendar.xml' );
97
98 $html .= join("\n", map { $vevents->{$_} } sort keys %$vevents );
99
100 $html .= qq|
101
102 <a href="calendar.xml">rss</a>
103
104 </body>
105 </html>
106
107 |;
108
109 write_file 'www/calendar.html', $html;