"""Display the contents of a newsgroup""" # 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 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import config, os, sys, string, cgi, urllib, nnthread, mimify, time from cStringIO import StringIO NL = '\015\012' OF=StringIO() cfg=config.config() scriptname = os.environ['SCRIPT_NAME'] rh = cfg.connect() reqinfo = string.split(urllib.unquote(os.environ['QUERY_STRING']), ',') if not reqinfo or reqinfo[0] == '': raise TypeError, 'Must supply a newsgroup name.' try: resp, count, first, last, name = rh.group(reqinfo[0]) except: raise IOError, "Newsgroup `%s' not found." % reqinfo[0] reqwhole = string.join(reqinfo[:2], ',') # This could use some rethinking. Later. try: himark = int(reqinfo[1]) except: himark = int(last) if himark < int(first): himark = int(first) elif himark > int(last): himark = int(last) lomark = himark - 300 if lomark < int(first): lomark = int(first) prevhi = 0 else: prevhi = lomark -1 novresult, novlist = rh.xover(str(lomark), str(himark)) havenews = 1 try: lomark = int(novlist[-100][0]) thread = nnthread.Threader(rh, novlist[-100:]) except: try: lomark = int(novlist[0][0]) thread = nnthread.Threader(rh, novlist) except: havenews = 0 OF.write('Content-Type: text/html%s%s%s%s - group%s' % (NL, NL, cfg.doctype, config.name, cfg.body)) try: ngdesc = rh.list(('newsgroups', rh.groupname))[1][0][1] except: ngdesc = '(no description is available)' try: modflag = rh.list(('ACTIVE', rh.groupname))[1][0][-1] except: modflag='' if modflag == 'm': modflag = "*Moderated*" else: modflag = '' OF.write('[%s]' % (scriptname, config.name)) if int(first) < int(lomark): OF.write(' - [Older]' % (scriptname, rh.groupname, int(lomark))) else: OF.write(' - [Older]') if int(last) > int(himark): OF.write(' [Newer]' % (scriptname, rh.groupname, int(himark) + 99)) else: OF.write(' [Newer]') OF.write(' - [Look for FAQs]') OF.write(' [Post a New Message]' % (scriptname, rh.groupname)) OF.write('

%s %d-%d

' % (rh.groupname, lomark, himark)) OF.write('%s %s
' % (modflag, ngdesc)) if havenews: OF.write('
KBytes T Subject'
             + '                                           From' + NL)
    for item in thread.arttable:
        if item[1][2] != [] and not item[3][1]:
            if len(item[1][2]):
                star = 'T' \
                       % (scriptname, reqwhole, item[0],
                          string.join(item[1][3], '.'))
            else:
                star = '-'
        else:
            star = ' '
        if item[3][1]:
            star = item[3][1][:29] + '>'
        if star[0:2] == '%s %s%s'
                 % (item[3][0], star, scriptname, reqwhole, item[0],
                    subj, fromaddr[:20], NL))
    del thread
else:
    OF.write('

No articles found.

') OF.write('
' + NL) OF.seek(0) sys.stdout.write(OF.read()) OF.close() rh.quit()