To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.admin.generalOpen lugnet.admin.general in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Administrative / General / 5304
5303  |  5305
Subject: 
Pseudo-streaming live news (was: Re: Monitor Page)
Newsgroups: 
lugnet.admin.general
Date: 
Fri, 17 Mar 2000 22:57:04 GMT
Viewed: 
1391 times
  
In lugnet.admin.general, Steve Bliss writes:
Are you looking for something more along the lines of an instant "news
ticker" type of thing?

Yah, I think.  What I was really thinking of is a live list of the
most-recent messages.  As new messages get posted, the server sends them
down to my browser.

I was surprised how easy it was to devise a little pseudo-news-streamer --
both on the server end and on the client end.

All a client has to do is poll a special URL periodically and check the global
article count.  If the count has changed, the client requests (over HTTP) a
copy of all the new articles since the last count (the client must maintain
its own count).  Then the client displays the messages however it pleases --
as subject lines, or snippets, or whole messages with paging.

If you want to give this a try, here is the API:


AT STARTUP

   http://www.lugnet.com/news/avid.cgi

   Fetch this URL -once- at startup and it tells you the global article count
   (for example, 118253).  The format of the returned document is of type

      text/plain

   and the content is a single number followed by a newline (\012):

      [0-9]+\n


SUBSEQUENT POLLING

   http://www.lugnet.com/news/avid.cgi?n=N

   Fetch this URL _periodically_ (no more than once per minute!).  It returns
   to you all articles posted _after_ N.  Replace N with the number of the
   last article you received, or with the global article count retrieved at
   startup.  For example...

   http://www.lugnet.com/news/avid.cgi?n=118253

   By default, only article headers are sent.  (Headers average approximately
   1/2 KB each.)  If you want to retrieve article bodies as well as headers,
   you can optionally specify the maximum body size in bytes.  Bodies larger
   than this number are truncated to that size.  (A trailing \n at the very
   end of the last line is always guaranteed.)  For example:

   http://www.lugnet.com/news/avid.cgi?n=118253&b=1024       (chop past 1 KB)
   http://www.lugnet.com/news/avid.cgi?n=118253&b=10240      (chop past 10 KB)
   http://www.lugnet.com/news/avid.cgi?n=118253&b=1048576    (chop past 1 MB)

   The output is a simple easy-to-parse article list...

      list        ::=  article*

      article     ::=  artnum \n
                       ( head* \n body )?
                       \. \n

      artnum      ::=  [0-9]+

      head        ::=  headerline*

      headerline  ::=  key : value \n

      body        ::=  bodyline*

      bodyline    ::=  ( \. [^\n]+ \n | [^\.\n] [^\n]* \n )

      key         ::=  [^:]+

      value       ::=  [^\n]*

   In other words, the list consists of a series of articles.  Each article
   consists of an article number (on its own line), followed by the article's
   header lines, followed by a pure blank line, followed by the article's body,
   and followed finally by a period (".") on its own line.  If the article has
   been cancelled, the head and body are omitted, and the period-on-its-own-
   line immediately follows the article number.

   There is one thing special to note about the body lines:  Lines beginning
   with a period (".") need to be un-escaped back to their original form by
   removing the leading period, which was added in transit to ensure that it
   didn't accidentally wind up as the single-period end-of-body marker.

   At most, 20 articles are returned in one bundle.  You can call again for
   subsequent bundles, but please put your polling process to SLEEP for at
   least 60 seconds once you hit the end!

   Well, that's it!  The rest of the smarts are up to the client.  Now let's
   look at a simple client written in Perl.


AN EXAMPLE CLIENT

   Below is a Q&D ("quick & dirty") -- but actually working -- client which
   implements a "streaming" LUGNET newsreader.  It checks for new articles
   once every five minutes, and then dumps them to stdout.  The polling cycle
   is momentarily dropped to one minute if new articles are found, then it
   goes back up to five minutes again once new articles stop appearing.

   Depending on the I/O routines of your operating system, you might be able
   to pipe the output of this program to a pager such as 'more' or 'w3m' for
   a bit more interactivity.


--Todd

-------8<--------8<--------8<------ cut here ------8<--------8<--------8<------

#!/bin/perl
# Simple "streaming" LUGNET newsreader.

no strict; $^W = 0;  # Quick & Dirty mode
use LWP::Simple;

$\ = "\n";

$url = "http://www.lugnet.com/news/avid.cgi";
$N = get $url; $N or die; chop $N; print $N;

for (;;) { sleep(spit(suck())); }

sub suck { split /\n/, get "$url?b=1000000&n=$N" }

sub spit
{
   my $time = @_? 60:300;
   while (@_)
   {
      $N = shift; $N =~ m/^[0-9]+$/ or die;
      shift, next if $_[0] eq '.';
      print "\a", "_" x 79;
      while (defined($_ = shift)) { print; last if m/^$/; }
      while (defined($_ = shift)) { last if m/^\.$/; print; }
   }
   $time;
}

__END__



Message has 4 Replies:
  Re: Pseudo-streaming live news (was: Re: Monitor Page)
 
(...) Oops. That should say: article ::= artnum \n ( head \n body )? \. \n (no * after the head) --Todd (24 years ago, 17-Mar-00, to lugnet.admin.general)
  Re: Pseudo-streaming live news (was: Re: Monitor Page)
 
[snipped everything about the pseudo-streaming stuff] Cool! I didn't reply to this sooner, because copying the example client code, pasting it to a file, and running it through perl pretty much exhausted my Perl knowledge. I must play with this some (...) (24 years ago, 21-Mar-00, to lugnet.admin.general)
  Re: Pseudo-streaming live news (was: Re: Monitor Page)
 
In lugnet.admin.general, Todd Lehman wrote: [snipped all the cool stuff] OK, one more request. Feel free to blow this off if it's too much of a time-sink. Would it be possible to have avid.cgi serve up the html streams used to build the (...) (24 years ago, 21-Mar-00, to lugnet.admin.general)
  Re: Pseudo-streaming live news (was: Re: Monitor Page)
 
(...) Hey, Todd: I just wanted to say thanks for putting together the avid.cgi interface. It's very nifty and cool, even if I don't write a local newsspooler to attach to it. My little app polls through avid, and shows a list of the most recent (...) (24 years ago, 24-Mar-00, to lugnet.admin.general)

Message is in Reply To:
  Re: Monitor Page
 
(...) OK, as long as you've thought about it. (...) Yah, I think. What I was really thinking of is a live list of the most-recent messages. As new messages get posted, the server sends them down to my browser. Steve (24 years ago, 17-Mar-00, to lugnet.admin.general)

66 Messages in This Thread:























Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR