Created
March 24, 2013 13:29
-
-
Save rturowicz/5231984 to your computer and use it in GitHub Desktop.
usenet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import nntplib | |
import string | |
from email.parser import Parser | |
SERVER = "news.home.net.pl" | |
GROUP = "pl.comp.lang.python" | |
PORT = 119 | |
USER = "xxx" | |
PASSWORD = "xxx" | |
try: | |
server = nntplib.NNTP(SERVER, PORT, USER, PASSWORD) | |
# server welcome message | |
print server.getwelcome() | |
# group description | |
print server.description(GROUP) | |
# group data | |
resp, count, first, last, name = server.group(GROUP) | |
print "grpup: %s (%s)" % (name, count) | |
# get one message | |
print "first (%s):" % first | |
resp, id, message_id, text = server.head(last) | |
resp, id, message_id, text = server.article(id) | |
message = Parser().parsestr(string.join(text, "\n")) | |
print "body: %s" % message.get_payload() | |
# last 10 articles | |
resp, items = server.xover(str(int(last)-10), last) | |
for id, subject, author, date, message_id, references, size, lines in items: | |
print "msg_id: %s subject: %s, author: %s" % (id, subject, author) | |
resp, id, message_id, text = server.article(id) | |
message = Parser().parsestr(string.join(text, "\n")) | |
print "body: %s" % message.get_payload() | |
except NNTPError, e: | |
print e.message | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment