http://www.perlmonks.org?node_id=207731

I used to spend a lot of my time reading news sites. Now I spend all of my time doing it. But seriously, I found it was eating into my day, and so I resolved to get most of it over with first thing in the morning by having web pages sent to my inbox from a cron job.

What follows is my script to do this. I've ripped out various installation-specific bits, but it should still work. If I were to rewrite it, I'd probably use File::Temp to handle the temporary files rather than rely on unixisms.

Here's the code. Don't do anything annoying with it; good monks don't do that.

#!/usr/bin/env perl # mailwebpage - send a web page to someone over e-mail # created on 30/8/02001, and badly munged later. # # usage: takes two args; URL, and destination address # example: # mailwebpage http://www.tedious.com someone@elsewhere.com # if the URL happens to be a readable file, it does the right thing. use strict; use warnings; use diagnostics; use integer; use MIME::Lite; use LWP::Simple; my $url=shift; # web location if (-r $url) { # if URL is actually a file, $url = 'file:' . $url; # make it so # this'll probably foul up if we get a fs that can resolve urls... } my $recipient=shift; # e-mail recipient my @headarr = head($url); # get the http header if ($#headarr == -1) { die "Can't resolve $url\n"; # if there is nothing there } else { my $tmpfile = "/tmp/foo$$.tmp"; # actual tmp file name on system my $type = $headarr[0]; # Content-Type: getstore($url,$tmpfile); # get page to tmp file my $msg = new MIME::Lite # new mail object To =>$recipient, Subject =>$url, # URL is e-mail subject Type =>$type, Encoding =>'base64', Disposition =>'inline', Path =>$tmpfile; # these fields rooted out from old NS Communicator headers $msg->attr('Content-Base' => $url); $msg->attr('Content-Location' => $url); my $result = $msg->send; unlink $tmpfile; # better tell the good people what went down die "Can't send $url to $recipient\n" unless (defined($result)); } exit;

--
$,="\n";foreach(split('',"\3\3\3c>\0>c\177cc\0~c~``\0cc\177cc")) {$a++;$_=unpack('B8',$_);tr,01,\40#,;$b[$a%6].=$_};print@b,"\n"

  • Comment on Spend Less Time Surfing: Pages In Your Inbox with LWP::Simple and MIME::Lite
  • Download Code

Replies are listed 'Best First'.
Re: Spend Less Time Surfing: Pages In Your Inbox with LWP::Simple and MIME::Lite
by Azhrarn (Friar) on Oct 28, 2002 at 16:31 UTC
    Nice, though you may be interested in the news aggregator program Amphetadesk.
    Written in perl for just such news junkies as yourself. ;)
      Looks neat. I've been using SiteScooper for that sort of thing. Collins Dictionaries use Sitescooper to collect news text for corpus linguistics purposes.

      Did I need to say that SiteScooper is written in Perl?

      --
      $,="\n";foreach(split('',"\3\3\3c>\0>c\177cc\0~c~``\0cc\177cc")) {$a++;$_=unpack('B8',$_);tr,01,\40#,;$b[$a%6].=$_};print@b,"\n"

      I love Amphetadesk. PerlMonks is one of the only sites I actually visit anymore, everything else I mostly read the feed. No ads, just info. Kind of like a newspaper customized for you.

      Whoah, sounds kind of like the portal vision of yesteryears, before they filled every nook and cranny with banner ads and popups.
Re: Spend Less Time Surfing: Pages In Your Inbox with LWP::Simple and MIME::Lite
by cacharbe (Curate) on Oct 25, 2002 at 12:40 UTC