Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: RFC fetcher

by neophyte (Curate)
on Apr 04, 2001 at 13:38 UTC ( [id://69596]=note: print w/replies, xml ) Need Help??


in reply to RFC fetcher

I was looking for some rfc today so I thought I might use your code.
Of course I modified it, because I want to keep the rfc's I get. So I added a check if that rfc exists in my rfc-directory, if not it gets the rfc and writes it to a file. Works nicely.
I would like to prepend a search tool for the index, so you can search for a rfc by topic. Perhaps I'll add that when I have more time.

neophyte Niederrhein.pm

Replies are listed 'Best First'.
Re(2): RFC fetcher
by yakko (Friar) on Apr 04, 2001 at 21:29 UTC
    Great ideas! Here's my implementation of the first idea:
    #!/usr/bin/perl -w # example usage: rfc 1459 (gets the IRC RFC) use strict; use LWP::Simple qw(get); die("usage: rfc <rfc#>\n") unless defined($ARGV[0]); my $rfcnum=$ARGV[0]; my $base="http://www.rfc.net/rfc"; my $rfcdir="$ENV{HOME}/rfcs"; my $rfcfile="${rfcdir}/rfc${rfcnum}.txt"; my $rfc; if(-e $rfcfile) { open(RFC,"<$rfcfile") or die("open($rfcfile): $!\n"); local $/ = undef; $rfc=<RFC>; close(RFC); } else { $rfc=get($base.$rfcnum.".txt"); open(RFC,">$rfcfile") or die("open($rfcfile): $!\n"); print RFC "$rfc"; close(RFC); } print "$rfc"; __END__
    (Update: Just when I thought I had it nailed, better ideas crop up. Now reading docs to retool to merlyn's idea below. (tho rfc.net doesn't appear to return the proper headers that support mirror()))

    --
    Me spell chucker work grate. Need grandma chicken

      I'd use LWP::Simple's mirror($url, $localfile) in place of the if/else test. That way, if they update it, you'll get the latest version, and if it hasn't changed, it's still minimal traffic. It also automatically avoids creating the local file if the remote fetch failed, so you won't end up with an empty RFC file if something's broken.

      -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69596]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found