Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Calculates nntp stats
#!/usr/bin/env python
import nntplib
import re
import sys
usage = """./nntp-stats [nntp-group-name]"""
if len(sys.argv) < 2:
print usage
newsgroup = sys.argv[1]
s = nntplib.NNTP('')
(resp, count, first, last, name) =
resp, items = s.xover(first, last)
count = 0
posting_from_mozilla = 0
posting_from_googlegroups = 0
posting_from_other = 0
article_date = []
for id, subject, author, date, message_id, references, size, lines in items:
# Count number of total messages
count += 1
# This is a terrible way of getting this data
# if message id has the word
# we assume its from
# otherwise if it has the word and mailman then its from mailman
# everything else we assume its from nntp
if re.findall(r'', message_id):
posting_from_googlegroups += 1
elif re.findall(r'', message_id) and re.findall(r'mailman', message_id):
posting_from_mozilla +=1
posting_from_other += 1
percent_mozilla = (float(posting_from_mozilla)*100/float(count))
percent_googlegroups = (float(posting_from_googlegroups)*100/float(count))
percent_other = (float(posting_from_other)*100/float(count))
print "Total number of articles: %s" % count
print "Message from mailman: %s (%d%%)" % (posting_from_mozilla, int(percent_mozilla))
print "Message from google groups %s (%d%%)" % (posting_from_googlegroups, int(percent_googlegroups))
print "Message from other: %s (%d%%)" % (posting_from_other, int(percent_other))
print "First message date: %s" % (article_date[0])
print "Last message date: %s" % (article_date[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment