Skip to content

Instantly share code, notes, and snippets.

@limed
Last active May 23, 2016 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save limed/d42a3c633e62b2639d1d0c1eb4dadbbd to your computer and use it in GitHub Desktop.
Save limed/d42a3c633e62b2639d1d0c1eb4dadbbd to your computer and use it in GitHub Desktop.
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
sys.exit(1)
newsgroup = sys.argv[1]
s = nntplib.NNTP('news.mozilla.org')
(resp, count, first, last, name) = s.group(newsgroup)
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
article_date.append(date)
# if message id has the word googlegroups.com
# we assume its from groups.google.com
# otherwise if it has the word lists.mozilla.org and mailman then its from mailman
# everything else we assume its from nntp
if re.findall(r'googlegroups.com', message_id):
posting_from_googlegroups += 1
elif re.findall(r'lists.mozilla.org', message_id) and re.findall(r'mailman', message_id):
posting_from_mozilla +=1
else:
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])
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment