summaryrefslogtreecommitdiffstats
path: root/make-rss
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2013-07-24 15:08:52 +0200
committerGravatar Steven Schubiger <stsc@refcnt.org> 2013-07-24 15:08:52 +0200
commit3db8326946100a54d5891f5bf1de62676c94833c (patch)
treeebc17a755e5c47f523b8ad3b13d81d481d3dbf15 /make-rss
parentf03ccc18f5ea460ffe5f6be40f422e5fd05b5e7a (diff)
downloadlugs-3db8326946100a54d5891f5bf1de62676c94833c.tar.gz
lugs-3db8326946100a54d5891f5bf1de62676c94833c.tar.bz2
make-rss: initial commit
Diffstat (limited to 'make-rss')
-rwxr-xr-xmake-rss/make-rss.pl102
1 files changed, 102 insertions, 0 deletions
diff --git a/make-rss/make-rss.pl b/make-rss/make-rss.pl
new file mode 100755
index 0000000..9505dad
--- /dev/null
+++ b/make-rss/make-rss.pl
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Author: Steven Schubiger <stsc@refcnt.org>
+# Last modified: Wed Jul 24 14:45:23 CEST 2013
+
+use strict;
+use warnings;
+use lib qw(lib);
+
+my $VERSION = '0.01';
+
+my $Config = {
+ base_url => 'http://www.lugs.ch/lugs/termine/',
+ language => 'de',
+ input => './termine.txt',
+ output => './termine.rss',
+ title => 'LUGS Terminliste',
+ webmaster => 'www@lugs.ch',
+};
+
+{
+ my $rss = LUGS::Termine::RSS->new;
+
+ $rss->init;
+ $rss->process_content;
+ $rss->save_rss;
+}
+
+package LUGS::Termine::RSS;
+
+use constant true => 1;
+
+use LUGS::Events::Parser ();
+use XML::RSS::SimpleGen ();
+
+sub new
+{
+ my $class = shift;
+
+ return bless {};
+}
+
+sub init
+{
+ my $self = shift;
+
+ $self->{rss} = XML::RSS::SimpleGen->new($Config->{base_url}, $Config->{title});
+
+ $self->{rss}->allow_duplicates(true);
+ $self->{rss}->language($Config->{language});
+ $self->{rss}->webmaster($Config->{webmaster});
+}
+
+sub process_content
+{
+ my $self = shift;
+
+ my $parser = LUGS::Events::Parser->new($Config->{input});
+
+ while (my $event = $parser->next_event) {
+ my $year = $event->get_event_year;
+ my $month = $event->get_event_month;
+ my $day = $event->get_event_day;
+
+ my $date = join '.', ($day, $month, $year);
+ my $full_date = join ', ', ($event->get_event_weekday, $date);
+
+ my $title = join ', ', ($full_date, $event->get_event_time, $event->get_event_title);
+ my $desc = join ' ', ($event->get_event_location, $event->get_event_more || ());
+
+ $self->save_item($Config->{base_url}, $event->get_event_anchor, $title, $desc);
+ }
+}
+
+sub save_item
+{
+ my $self = shift;
+ my ($url, $anchor, $title, $desc) = @_;
+
+ $self->{rss}->item("$url#$anchor", $title, $desc);
+}
+
+sub save_rss
+{
+ my $self = shift;
+
+ $self->{rss}->save($Config->{output});
+}