Posted By

xxtjaxx on 12/04/09


Tagged

perlRSSxmllow


Versions (?)

Adding a new RSS entry to your feed


 / Published in: Perl
 

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.

  1. #! /usr/bin/perl -w
  2. # Given that your blog post will look a bit like this and the "essay" for the rss feed is in
  3. # a html comment like this:
  4. ###########################################################################################
  5. # <html>
  6. # <h1>Hello World!</h1>
  7. # <!--
  8. # # Hello World!
  9. # ~ Its is amazing what is possible with a bit of knowledge about
  10. # ~ C/C++, Perl, Shellscripting(Bash) and Unix based systems.
  11. # -->
  12. # Its is amazing what is possible with a bit of knowledge about
  13. # C/C++, Perl, Shellscripting(Bash) and Unix based systems.
  14. ###########################################################################################
  15. # The hash(#) and the tilde (~) are used as the line delimiters between RSS Feed Item
  16. # Title(#) and Content(~).
  17.  
  18. use strict;
  19. use warnings;
  20. if( $ARGV[0]=~ m/\-\-help/ )
  21. {
  22. print "Usage: [POST] [FEEDFILE]\n";
  23. exit 0;
  24. }
  25. open (my $postH , $ARGV[0]);
  26. my $title="";
  27. my $body="";
  28. # parse blog post for rss feed data
  29. while(<$postH>)
  30. {
  31. if(m/\#/)
  32. {
  33. $title=$title.$_;
  34. }
  35. if(m/\~/)
  36. {
  37. $body=$body.$_;
  38. }
  39. }
  40. close($postH);
  41.  
  42. $title=~ s/\#//g;
  43. $body=~ s/\~//g;
  44. # put parse data in the feed string
  45. my $rssfile="";
  46. open(my $rssfeedH, $ARGV[1] );
  47. while(<$rssfeedH>)
  48. {
  49. my $temp=$_;
  50. if( m/pastehere/ )
  51. {
  52. $title="<title>\t".$title."</title>";
  53. $body="<description>\t".$body."\n</description>";
  54. my $guid=$ARGV[0];
  55.  
  56. #$guid=~ s:/?*\/?*::g;
  57. my $link="http://www.xxtjaxx.org/".$guid;
  58. $guid="<guid>\n\t".$guid."\n</guid>";
  59. # Sun, 22 Nov 2009 02:15:48 +0000
  60. my $date = `date +%a_,%d_%b_%Y_%k:%M:%S_%z`;
  61. $date=~ s/_/\ /g;
  62. my $pubdate="<pubDate>\t".$date."</pubDate>";
  63. $temp="<!--pastehere-->\n"."<item>\n".$title."\n".$guid."\n".$body."\n".$pubdate."\n"."</item>\n";
  64.  
  65. }
  66. if ($temp =~ m/\n/ )
  67. {
  68. $rssfile=$rssfile.$temp;
  69. }
  70. else
  71. {
  72. $rssfile=$rssfile."\n".$temp;
  73. }
  74. }
  75. close($rssfeedH);
  76. print $rssfile;
  77. open(my $rssH , ">$ARGV[1]");
  78. print $rssH $rssfile;
  79. close($rssH);
  80. exit 0;

Report this snippet  

You need to login to post a comment.