make-rss: initial commit
[lugs.git] / make-rss / make-rss.pl
1 #!/usr/bin/perl
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 #
17 # Author: Steven Schubiger <stsc@refcnt.org>
18 # Last modified: Wed Jul 24 14:45:23 CEST 2013
19
20 use strict;
21 use warnings;
22 use lib qw(lib);
23
24 my $VERSION = '0.01';
25
26 my $Config = {
27 base_url => 'http://www.lugs.ch/lugs/termine/',
28 language => 'de',
29 input => './termine.txt',
30 output => './termine.rss',
31 title => 'LUGS Terminliste',
32 webmaster => 'www@lugs.ch',
33 };
34
35 {
36 my $rss = LUGS::Termine::RSS->new;
37
38 $rss->init;
39 $rss->process_content;
40 $rss->save_rss;
41 }
42
43 package LUGS::Termine::RSS;
44
45 use constant true => 1;
46
47 use LUGS::Events::Parser ();
48 use XML::RSS::SimpleGen ();
49
50 sub new
51 {
52 my $class = shift;
53
54 return bless {};
55 }
56
57 sub init
58 {
59 my $self = shift;
60
61 $self->{rss} = XML::RSS::SimpleGen->new($Config->{base_url}, $Config->{title});
62
63 $self->{rss}->allow_duplicates(true);
64 $self->{rss}->language($Config->{language});
65 $self->{rss}->webmaster($Config->{webmaster});
66 }
67
68 sub process_content
69 {
70 my $self = shift;
71
72 my $parser = LUGS::Events::Parser->new($Config->{input});
73
74 while (my $event = $parser->next_event) {
75 my $year = $event->get_event_year;
76 my $month = $event->get_event_month;
77 my $day = $event->get_event_day;
78
79 my $date = join '.', ($day, $month, $year);
80 my $full_date = join ', ', ($event->get_event_weekday, $date);
81
82 my $title = join ', ', ($full_date, $event->get_event_time, $event->get_event_title);
83 my $desc = join ' ', ($event->get_event_location, $event->get_event_more || ());
84
85 $self->save_item($Config->{base_url}, $event->get_event_anchor, $title, $desc);
86 }
87 }
88
89 sub save_item
90 {
91 my $self = shift;
92 my ($url, $anchor, $title, $desc) = @_;
93
94 $self->{rss}->item("$url#$anchor", $title, $desc);
95 }
96
97 sub save_rss
98 {
99 my $self = shift;
100
101 $self->{rss}->save($Config->{output});
102 }