From: Anthony Papillion on
I'm new to NNTPLib (and Python) and I'm experiencing some behavior I
can't understand. I'm writing a program to analyze newsgroup subject
which will then produce statistics on topics discussed. For my
example, I'm using this group (comp.lang.python) and trying to simply
print out all of the subjects listed in the group.

This is the code I'm using:

resp, count, first, last, name = server.group('comp.lang.python')
resp, items = server.xover(first, last)

for subject in items:
resp, subject = server.xhdr('subject', first, last)
print subject

While the loop will indeed LOOP through all of the items, the print
statement generates unprintable character (they look like [] in the
terminal window.

What am I doing wrong? I've looked at the doc and it looks like this
is how I'd call it. Am I missing something?

Thanks!
Anthony
From: Tim Wintle on
On Tue, 2010-06-08 at 08:24 -0700, Anthony Papillion wrote:
> resp, count, first, last, name = server.group('comp.lang.python')
> resp, items = server.xover(first, last)
>
> for subject in items:
> resp, subject = server.xhdr('subject', first, last)
> print subject
>
> While the loop will indeed LOOP through all of the items, the print
> statement generates unprintable character (they look like [] in the
> terminal window.

"[]" is the way python prints an empty list.

I don't know NNTPLib, but I'm guessing you don't want to be throwing
away the subject variable, so you either want

for subject in items:
print subject

or

for subject in items:
resp, sub = server.xhdr("subject", first, last)
print sub

- the second will do the same as your current code, I don't know how
NNTPLib returns the subject or what the list it's returning represents.

From: Anthony Papillion on
Hi Tim,

Tried both and neither works. While I really believe it's simply the
wrong code, I'm wondering if my news server might be throwing
something invalid into the header or not conforming to RFC standards.
Thanks for taking a shot at this anyway though.

Anyone have any other thoughts on why this isn't working?
From: Thomas Jollans on
On 06/08/2010 05:24 PM, Anthony Papillion wrote:
> I'm new to NNTPLib (and Python) and I'm experiencing some behavior I
> can't understand. I'm writing a program to analyze newsgroup subject
> which will then produce statistics on topics discussed. For my
> example, I'm using this group (comp.lang.python) and trying to simply
> print out all of the subjects listed in the group.
>
> This is the code I'm using:
>
> resp, count, first, last, name = server.group('comp.lang.python')
> resp, items = server.xover(first, last)
>
> for subject in items:
> resp, subject = server.xhdr('subject', first, last)
> print subject
>
I just had a quick look at the documentation. It looks like you should
re-read it.
http://docs.python.org/py3k/library/nntplib.html#nntplib.NNTP.xhdr

xhdr returns a whole list. It looks like you'd need something like

resp, subjects = server.xhdr('subject', '{0}-{1}'.format(first, last))
for sub in subjects:
print (sub)

you should also have another close look at the documentation of xover:
http://docs.python.org/py3k/library/nntplib.html#nntplib.NNTP.xover

and then maybe write something like this:

resp, items = server.xover(first, last)
subjects = (info[1] for info in items)
for s in subjects:
print (s)

Have fun,
Thomas

PS: my untested code here was sketched up with Python 3.x in mind. You
might have to change one or two things for it to work on older versions.

> While the loop will indeed LOOP through all of the items, the print
> statement generates unprintable character (they look like [] in the
> terminal window.
>
> What am I doing wrong? I've looked at the doc and it looks like this
> is how I'd call it. Am I missing something?
>
> Thanks!
> Anthony
>

From: Anthony Papillion on

> I just had a quick look at the documentation. It looks like you should
> re-read it.http://docs.python.org/py3k/library/nntplib.html#nntplib.NNTP.xhdr

<snip>

Thank you for the help Thomas. I did reread the doc and I see what you
mean. I think this will work now. Much thanks for the help!

Anthony