listing23-1.py 488 B

1234567891011121314151617181920212223
  1. from nntplib import NNTP
  2. servername = 'news.foo.bar'
  3. group = 'comp.lang.python.announce'
  4. server = NNTP(servername)
  5. howmany = 10
  6. resp, count, first, last, name = server.group(group)
  7. start = last - howmany + 1
  8. resp, overviews = server.over((start, last))
  9. for id, over in overviews:
  10. subject = over['subject']
  11. resp, info = server.body(id)
  12. print(subject)
  13. print('-' * len(subject))
  14. for line in info.lines:
  15. print(line.decode('latin1'))
  16. print()
  17. server.quit()