Trivial Lifehacker Profile Monitoring Script
Lifehacker is a site that many of us watch daily for tips. If you join the community, you may find that the LH site can sometimes become … er … slow. The cause of this can be many things, but personally, I think they’ve gone overboard with all the javascript.
Someone mentioned they had written a real-time notification script to tell him about relies to his posts and he asked others what they would like of the script. I started thinking and determined it would be a fairly trivial script to do what I wanted – email a list of replies in simple HTML.
As with all scripts, they are never really done and prone to tweaks for the next year. I think the next tweak will be to try the feed.xml that LH provides. Perhaps it will be smaller, faster and easier to parse?
So I attempted to attach the script to this article using tools build into the blogging system. Both have failed.
- Upload – so RSS feed readers see an attachment link – no joy
- Excerpt – I’ve used this in previous versions of the blog successfully. No more. The issue is probably due to my theme.
Anyway, here’s the code
#!/usr/bin/perl
- #####################################################
- Display Lifehacker Profile data
- Recent Replies (first pg only)
- Followers
- Friends
#- Known Linux Dependencies:
- - perl and LWP and Getopt modules
- - sudo cpan -i LWP::Simple
#- Installation
- 1) Change the Your-LH-Profile-name-Here below to yours
- 2) chmod +x lh_profile_monitor.cgi
- 3a) Either run as is $0 > output.html
- Or
- 3b) Setup as a CGI on your web server
- Or
- 3c) Setup as a crontab entry which will automatically email the results
#- $Id: lh_profile_monitor.cgi,v 1.5 2009/12/16 14:32:55 jdfsdp Exp jdfsdp $
#- #####################################################
use strict;
use LWP::Simple;
use Getopt::Long;
- #####################################################
sub life_hacker_data();
- #####################################################
my $profile_name=“Your-LH-Profile-name-Here”;
my $doHelp = 0;
my $download = 1;
my $profile_page=“http://lifehacker.com/people/$profile_name/”;- my $profile_page=“http://lifehacker.com/people/$profile_name/feed.xml”;
my $date=`date +%r`;
my $ret=GetOptions (“help|?” => \$doHelp,
“profile=s” => \$profile_name,
“download=i” => \$download);my $html_header = “Content-type: text/html\n\n
";
”refresh\" CONTENT=\“600\”>
$profile_name-Recent LifeHacker
my $html_footer = “”;
- ########################################################
sub Usage()
{
print “\nUsage:
$0 [-download 0/1] -profile LifeHacker_Profile\n”;
exit 1;
}
- #####################################################
- main()
- The output is a filtered html file to stdout
#- Grab the new page
Usage() if ( $doHelp );
- `/usr/local/bin/curl $profile_page > $profile_tmp_file` if ($download);
my $content = get( $profile_page ) if ($download);
my @lh_content = split(/\n/, $content);
print “$html_header\n”;
print “List of Recent Replied to Messages
Pulled from ”$profile_page\“>$profile_page at $date
- ”;
my $ret=life_hacker_data();
print “$ret\n”;
print “\n$html_footer\n\n”;
- #####################################################
sub life_hacker_data()
{- Display the total count of
- Friends
- Followers
- Msgs with replies
my $ret="";
foreach (@lh_content){
if (m#/friends/$profile_name|/followers/$profile_name|replied# ){
$ret .= $_;
}
}
$ret =~ s#
$ret =~ s#href=“/friends#href=”http://lifehacker.com/friends#g;
$ret =~ s#href=“/followers#href=”http://lifehacker.com/followers#g;
$ret =~ s#
#
#i;
$ret =~ s#^[.]Click here to view all[.]$##ig; # Remove excess lines
$ret =~ s#view all##ig; # Remove excess lines
$ret =~ s#»##ig; # Remove excess lines
return $ret;
}