#!/usr/bin/perl # linda macphee-cobb # http://herselfswebtools.com # # 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 backups up blogger comments from your rss feed. # # You must change http://www.bloggers.com/feeds/99999999/posts/default?max-results=500&alt=rss # Replace the 9999s with your blog id number. Log onto blogger. Go to posts and you'll see # BlogID= followed by a number in the URL bar of your browser. Just plug in that number and remove # the 9s ####################################################### # includes and globals ####################################################### #includes use strict; use LWP::Simple; # global variables my $content; my $file; # other globals ################################################################################ # Fetch rss stream for comments from all posts $_ = get ( "http://www.blogger.com/feeds/9999999999999999/comments/default?max-results=300&alt=rss"); ############################################################################################# # pull out all there is one for each post and put into an array for processing my @items = m/.*?<\/item>/g; # for each item in the array pull out the pubDate, description, link and how ever many images there many be foreach my $item ( @items ){ # pull posting date from entry $_ = $item; my @post_date = m/.*?<\/pubDate>/g; my $date = @post_date[0]; $date =~ s/<\/*pubDate>//g; #remove tags # pull comment title from entry my @comment_title_data = m/.*?<\/title>/g; my $comment = @comment_title_data[0]; $comment =~ s/<\/*title.*?>//g; # pull actual comment from entry my @comment_data = m/<description>.*?<\/description>/g; my $comment = @comment_data[0]; $comment =~ s/<\/*description>//g; # remove tags $comment =~ s/</</g; # replace < with < $comment =~ s/>/>/g; # replace > with > # pull comment author from entry my @author_data = m/<author>.*?<\/author>/g; my $author = @author_data[0]; $author =~ s/<\/*author>//g; # pull the link to this file from item and link is the same as the file name my @link_data = m/<link>.*?<\/link>/g; my $link = @link_data[0]; $link =~ s/<\/*link>//g; # remove tags $link =~ s/http:\/\///; # remove http:// $link =~ s/"//g; # sometimes " are still on end of name $link =~ s/\.html#/\//; # remove .html# and replace with \ # pull out title of comment my @title_data = m/<title>.*?<\/title>/g; my $title = @title_data[0]; $title =~ s/<\/*title>//g; # create and save a file containing pubDate, description ( post ) name it with the link name # does directory exist? if not create it my @directories = split /\//, $link; $#directories--; # removes file name from end of path list my $checkDirectory = ""; # put each post in a directory by the month and year it was created foreach my $directory ( @directories ){ # need to check first and build path as we go or cd into directories as we go $checkDirectory .= $directory . "/"; if ( -e $checkDirectory ){ }else{ mkdir $checkDirectory, 0755; } } # create the file on the computer and write to the file open FILEHANDLE, ">$link"; print FILEHANDLE "\n <html><head><title> $title "; print FILEHANDLE "\n

$date

"; print FILEHANDLE "\n

$comment

"; print FILEHANDLE "\n

$author

"; print FILEHANDLE "\n"; close FILEHANDLE; }