"""Display a list of selected newsgroups""" # meoWWW # Copyright 1999 G.J. Andruk # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import config, os, sys, string from cStringIO import StringIO NL = '\015\012' OF = StringIO() cfg = config.config() scriptname = os.environ['SCRIPT_NAME'] rh = cfg.connect() try: reqinfo = string.split(os.environ['QUERY_STRING'])[0] except: raise TypeError, 'No group pattern supplied' try: actlist = rh.list(('ACTIVE', reqinfo))[1] except: actlist = [] actlist.sort() nghash = {} try: for group in rh.list(('NEWSGROUPS', reqinfo))[1]: if len(group) > 1: nghash[group[0]] = group[1] except: pass outbuf = StringIO() for group in actlist: if group[-1] == 'm': grpstat = 'Mod ' elif group[-1] == 'y': grpstat = 'open' else: continue artcount = int(group[1]) - int(group[2]) + 1 if artcount < 0: artcount = 0 try: ngdesc = nghash[group[0]] except: ngdesc = '(no description)' outbuf.write( '%10d %s %s %s%s' % (artcount, grpstat, scriptname, group[0], group[0], ngdesc, NL)) if outbuf.tell(): OF.write('Content-Type: text/html' + NL + NL + ('%s - list%s' % (config.name, cfg.body))) OF.write('[%s]' % (scriptname, config.name)) OF.write('

Newsgroups in %s

' % reqinfo + NL + '
  Articles  Stat  Name and Description
' + NL) outbuf.seek(0) OF.write(outbuf.read()) OF.write('
\n') outbuf.close() else: raise IOError, 'No newsgroups found in ' + reqinfo OF.seek(0) sys.stdout.write(OF.read()) OF.close() rh.quit()