saving NNTP bodies to disk

Daniel Daniel.Kinnaer at AdValvas.be
Tue Dec 26 18:20:43 EST 2000


Hello. I've come up with a small Python script but ran into trouble.
Here's what I'm trying to do : get a NNTP connection, get the last 10
headers AND bodies and save them to disk.  It seems I made an error: I
try to write a list to disk using f.write() and Python complains about
this with following report 

 f.write(TheBody[i])
TypeError: read-only character buffer, list

Below is the script. Can someone please explain me what I'm doing
wrong?  All help is greatly appreciated.  Thanks

print "Start script..."
from nntplib import *
print "### Ok! Starting to read from Skynet..."
s=NNTP('news.skynet.be')
resp, count, first,last,name = s.group('comp.lang.python')
print 'Group', name, 'has', count, 'articles, range', first, 'to',
last
resp, subs = s.xhdr('subject', first + '-' + last)

print "showing and saving only last 10 headers + bodies..."
for id, sub in subs[-10:]:
    print id, sub
    #save body to disk
    f=open( id,'w')      #how do I add an extension 'txt' ???
    TheBody=s.body(id)    
    f.write(sub)
    for i in range(0,len(TheBody)):
        print i,TheBody[i] #show on screen
        f.write(TheBody[i])
    f.close()
s.quit()
print "End of Script..."


best regards,

Daniel



More information about the Python-list mailing list