artist has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks
I have successfully usedNews::NNTPClient and MIME::Parser modules to get the data from NNTPServer and parse it. Question is how should I fetch the latest data throught the day periodically.
Update: ie..I am looking for some interface that fetches the articles only after certain times or let's say in last hour.

Thanks,

{artist}

Replies are listed 'Best First'.
•Re: Talking to NNTP server
by merlyn (Sage) on Nov 18, 2003 at 20:50 UTC
Re: Talking to NNTP server
by pg (Canon) on Nov 18, 2003 at 20:38 UTC

    NNTP spec supports this command for you get a list of article numbers received after a given time point:

    NEWNEWS newsgroups date time [GMT] [<distribution>]

    In your Perl script, just do something like:

    require News::NNTPClient; $c = new News::NNTPClient; foreach ($c->newnews("test", time - 3600)) { print $c->body($_); }

    You either run your script as a daemon, or use whatever scheduler you have to schedule it to run periodically.

    Update:

    If the news group you are trying to access falls in liz's description, then you have to remember the number of the last article, and next time, just start from there. Remember one thing, article number are not neccessary continuous, and your script has to expet this.

      Unfortunately, I haven't seen any NNTP server that supports this (at least not in the past 5 years). Most ISP's have switched this off because it causes too much load on the NNTP server. ;-(

      Liz

Re: Talking to NNTP server
by simonm (Vicar) on Nov 18, 2003 at 20:37 UTC
    Typically, by creating a script that does this and then adding a line to your system's crontab (or equivalent scheduling utility) that invokes your script ever hour, or as you desire.

    (I'm not sure I fully understood the question -- more context would be welcome...)

Re: Talking to NNTP server
by Itatsumaki (Friar) on Nov 18, 2003 at 20:43 UTC

    You could schedule it with your OS (e.g. a cron job, or using putting in a .bat file and using task-scheduler on Win32). Or you could start the program manually and use it in a loop like this:

    my $n = 10 * 60; while (1) { sleep $n; # sleep 10 minutes # do your stuff to get and parse newsgroup stuff }
Re: Talking to NNTP server
by artist (Parson) on Nov 18, 2003 at 22:16 UTC
    Thank you for all the answers:

    Here is the code that I am using.. I try to go with Newsrc file. I think it's the best option.

    use News::NNTPClient; use News::Newsrc; use strict; use warnings; my $newsrc = News::Newsrc->new("localfile"); my $ok = $newsrc->load("localfile"); my $server = 'myserver'; my $group = q(group); my $client = News::NNTPClient->new($server) my ($low,$high) = $client->group($group); my @unmarked = $newsrc->unmarked_articles($group,$low,$high); foreach my $artnum (@unmarked){ my $art = $client->article($artnum) or next; print $art,"\n"; $newsrc->mark($group,$artnum); } $newsrc->save_as("localfile")