Trivial Lifehacker Profile Monitoring Script

Posted by JD 12/16/2009 at 09:25

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.

  1. Upload – so RSS feed readers see an attachment link – no joy
  2. 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

  1. #####################################################
  2. Display Lifehacker Profile data
  3. Recent Replies (first pg only)
  4. Followers
  5. Friends
    #
  6. Known Linux Dependencies:
  7. - perl and LWP and Getopt modules
  8. - sudo cpan -i LWP::Simple
    #
  9. Installation
  10. 1) Change the Your-LH-Profile-name-Here below to yours
  11. 2) chmod +x lh_profile_monitor.cgi
  12. 3a) Either run as is $0 > output.html
  13. Or
  14. 3b) Setup as a CGI on your web server
  15. Or
  16. 3c) Setup as a crontab entry which will automatically email the results
    #
  17. $Id: lh_profile_monitor.cgi,v 1.5 2009/12/16 14:32:55 jdfsdp Exp jdfsdp $
    #
  18. #####################################################
    use strict;
    use LWP::Simple;
    use Getopt::Long;
  1. #####################################################
    sub life_hacker_data();
  1. #####################################################
    my $profile_name=“Your-LH-Profile-name-Here”;
    my $doHelp = 0;
    my $download = 1;
    my $profile_page=“http://lifehacker.com/people/$profile_name/”;
  2. 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 = “”;

  1. ########################################################
    sub Usage()
    {
    print “\nUsage:
    $0 [-download 0/1] -profile LifeHacker_Profile\n”;
    exit 1;
    }
  1. #####################################################
  2. main()
  3. The output is a filtered html file to stdout
    #
  4. Grab the new page
    Usage() if ( $doHelp );
  1. `/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
    1. ”;
      my $ret=life_hacker_data();
      print “$ret\n”;
      print “\n$html_footer\n\n”;
    1. #####################################################
      sub life_hacker_data()
      {
    2. Display the total count of
      1. Friends
      2. Followers
      3. Msgs with replies
        my $ret="";
        foreach (@lh_content){
        if (m#/friends/$profile_name|/followers/$profile_name|replied# ){
        $ret .= $_;
        }
        }
        $ret =~ s#
#
  • #g;
    $ret =~ s#href=“/friends#href=”http://lifehacker.com/friends#g;
    $ret =~ s#href=“/followers#href=”http://lifehacker.com/followers#g;
    $ret =~ s#

    #

  • \n

    #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;

    }

    Trackbacks

    Use the following link to trackback from your own site:
    https://blog.jdpfu.com/trackbacks?article_id=392