NNTP server : NNTP « Network « Python Tutorial






from nntplib import NNTP
from time import strftime, time, localtime

day = 24 * 60 * 60 

yesterday = localtime(time() - day)
date = strftime('%y%m%d', yesterday)
hour = strftime('%H%M%S', yesterday)

servername = 'news.foo.bar'
group = 'comp.lang.python.announce'
server = NNTP(servername)

ids = server.newnews(group, date, hour)[1]

for id in ids:
    head = server.head(id)[3]
    for line in head:
        if line.lower().startswith('subject'):
            subject = line[9:]
            break

    body = server.body(id)[3]

    print subject
    print '\n'.join(body)

server.quit()








21.10.NNTP
21.10.1.NNTP server