Return to Snippet

Revision: 21161
at December 4, 2009 19:06 by xxtjaxx


Initial Code
#! /usr/bin/perl -w
# Given that your blog post will look a bit like this and the "essay" for the rss feed is in
# a html comment like this:
###########################################################################################
# <html>
# <h1>Hello World!</h1> 
# <!--
#  # Hello World!
#  ~ Its is amazing what is possible with a bit of knowledge about 
#  ~ C/C++, Perl, Shellscripting(Bash) and Unix based systems.
# -->
# Its is amazing what is possible with a bit of knowledge about 
# C/C++, Perl, Shellscripting(Bash) and Unix based systems.
###########################################################################################
# The hash(#) and the tilde (~) are used as the line delimiters between RSS Feed Item
# Title(#) and Content(~). 

use strict;
use warnings;
if( $ARGV[0]=~ m/\-\-help/ )
{
    print "Usage: [POST] [FEEDFILE]\n";
    exit 0;
}
open (my $postH , $ARGV[0]);
my $title="";
my $body="";
# parse blog post for rss feed data
while(<$postH>)
{
    if(m/\#/)
    {
	$title=$title.$_;
    }
    if(m/\~/)
    {
	$body=$body.$_;
    }
}
close($postH);

$title=~ s/\#//g;
$body=~ s/\~//g;
# put parse data in the feed string
my $rssfile="";
open(my $rssfeedH, $ARGV[1] );
while(<$rssfeedH>)
{
    my $temp=$_;
    if( m/pastehere/ )
    {
	$title="<title>\t".$title."</title>";
	$body="<description>\t".$body."\n</description>";
	my $guid=$ARGV[0];
	
	#$guid=~ s:/?*\/?*::g;
	my $link="http://www.xxtjaxx.org/".$guid;
	$guid="<guid>\n\t".$guid."\n</guid>";
# Sun, 22 Nov 2009 02:15:48 +0000
	my $date = `date +%a_,%d_%b_%Y_%k:%M:%S_%z`;
	$date=~ s/_/\ /g;
	my $pubdate="<pubDate>\t".$date."</pubDate>";
	$temp="<!--pastehere-->\n"."<item>\n".$title."\n".$guid."\n".$body."\n".$pubdate."\n"."</item>\n";
	
    }
    if ($temp =~ m/\n/ ) 
    {
	$rssfile=$rssfile.$temp;
    }
    else
    {
	$rssfile=$rssfile."\n".$temp;
    }
}
close($rssfeedH);
print $rssfile;
open(my $rssH , ">$ARGV[1]");
print $rssH $rssfile;
close($rssH);
exit 0;

Initial URL


Initial Description
Lets say you have a small server. Its not really powerfull, it can not do much, but serve somebody some sites and an rss feed is allright.

Initial Title
Adding a new RSS entry to your feed

Initial Tags


Initial Language
Perl