bluto

Release package and announcement generator
Info | Log | Files | Refs | README | LICENSE

RSS.pm (3037B)


      1 package Bluto::RSS;
      2 
      3 use File::Spec;
      4 use DateTime;
      5 
      6 use XML::RSS;
      7 
      8 use Bluto::Log qw/error info debug warn trace/;
      9 use Bluto::Tree qw/announce_path/;
     10 
     11 
     12 sub get_feed_filepath {
     13 	my $release = shift;
     14 	my $env = shift;
     15 
     16 	my $fn = $release->{slug} . '.bluto.rss';
     17 	my $fp = File::Spec->catfile(Bluto::Tree->announce_path, $fn);
     18 	return $fp;
     19 }
     20 
     21 sub process {
     22 	my $release = shift;
     23 	my $env = shift;
     24 	my $body = shift;
     25 	my $force = 1;
     26 
     27 	$body =~ s#\n#<br/>#mg;
     28 	my $rss_title = $release->{slug} . ' ' . $release->{version};
     29 	my $rss;
     30 	$rss = XML::RSS->new;
     31 	my $feed_file = get_feed_filepath($release, $env);
     32 	if ( -f $feed_file ) {
     33 		info('found existing feed file ' . $feed_file);
     34 		$rss->parsefile( $feed_file );
     35 		foreach my $v ( @{$rss->{items}} ) {
     36 			debug('rss contains: ' . $v->{title});
     37 			if ($v->{title} eq $rss_title) {
     38 				error('already have rss entry for ' . $rss_title);
     39 				return undef;
     40 			}
     41 		}
     42 	} else {
     43 		info('starting new feed file ' . $feed_file);
     44 		$rss = XML::RSS->new(version => '1.0');
     45 		$rss->channel (
     46 			title => $release->{name},
     47 			link => $release->{uri},
     48 			description => $release->{summary},
     49 			guid => $release->{uri},
     50 			dc => {
     51 				subject => $release->{name},
     52 				rights => 'Copyright ' . $release->{copyright} . ' (License: ' . $release->{license} . ')',
     53 				license => $release->{license},
     54 				date => DateTime->now()->stringify(),
     55 				creator => $release->{_author_maintainer}[0],
     56 				publisher => $release->{_author_maintainer}[0],
     57 			},
     58 		#		subject    => "Linux Software",
     59 		#		creator    => 'scoop@freshmeat.net',
     60 		#		publisher  => 'scoop@freshmeat.net',
     61 		#		rights     => 'Copyright 1999, Freshmeat.net',
     62 		#		language   => 'en-us',
     63 		#	},
     64 		#	  taxo => [
     65 		#	       'http://dmoz.org/Computers/Internet',
     66 		#	            'http://dmoz.org/Computers/PC'
     67 		#	               ]
     68 		);
     69 	}
     70 
     71 	# check if we already have the title
     72 	foreach my $item ( $rss->{items}) {
     73 		if ( defined $item->[0] && $item->[0]{title} eq $rss_title ) {
     74 			error('already have published record for ' . $rss_title);
     75 			return undef;
     76 		}
     77 	}
     78 
     79 	info("releasetime ". $release->{time} . "\n");
     80 	$rss->add_item (
     81 		title => $rss_title,
     82 		link => $release->{src}[0],
     83 		description => $body,
     84 		mode => 'insert',
     85 		dc => {
     86 			date => $release->{time},
     87 		},
     88 	#  dc => {
     89 		#       subject  => "X11/Utilities",
     90 		#            creator  => "David Allen (s2mdalle at titan.vcu.edu)",
     91 		#               },
     92 		#                  taxo => [
     93 		#                       'http://dmoz.org/Computers/Internet',
     94 		#                            'http://dmoz.org/Computers/PC'
     95 		#                               ]
     96 	);
     97 
     98 	return $rss;
     99 }
    100 
    101 sub to_string {
    102 	my $release = shift;
    103 	my $env = shift;
    104 	my $body = shift;
    105 
    106 	my $rss = process($release, $env, $body);
    107 	if (!defined $rss) {
    108 		return undef;
    109 	}
    110 }
    111 
    112 sub to_file {
    113 	my $release = shift;
    114 	my $env = shift;
    115 	my $body = shift;
    116 
    117 	my $rss = process($release, $env, $body);
    118 	if (!defined $rss) {
    119 		return undef;
    120 	}
    121 	$rss->save(get_feed_filepath($release, $env));
    122 
    123 	return get_feed_filepath($release, $env);
    124 }
    125 
    126 1;