usenet statistics script....happy hacking!!!

Aaron K. Johnson akjmicro at yahoo.com
Sat Jan 25 23:40:05 CET 2003


If anyone improves this, repost to the community, please.

######## start here
####### newsdata, by Aaron K. Johnson <akj at 21stcentruy.net>

#!/PUT/YOUR/PYTHON/PATH/HERE

from nntplib import *
from string import find,split,join

########## change the data output file below:
outfile=open('put_your_data_file_here','w')
########## change the news server:
s=NNTP('news.whatever.whatever')

newsgroups=['comp.lang.ada', 'comp.lang.apl', 'comp.lang.asm.x86',
			'comp.lang.asm370', 'comp.lang.awk', 'comp.lang.basic.misc',
			'comp.lang.basic.powerbasic', 'comp.lang.basic.realbasic',
			'comp.lang.basic.visual.3rdparty',
			'comp.lang.basic.visual.announce',
			'comp.lang.basic.visual.database',
			'comp.lang.basic.visual.misc', 'comp.lang.beta', 'comp.lang.c',
			'comp.lang.c.moderated','comp.lang.c++', 'comp.lang.c++.leda',
			'comp.lang.c++.moderated', 'comp.lang.clarion',
			'comp.lang.clipper', 'comp.lang.clipper.visual-objects',
			'comp.lang.clos', 'comp.lang.clu', 'comp.lang.cobol',
			'comp.lang.dylan', 'comp.lang.eiffel', 'comp.lang.forth',
			'comp.lang.forth.mac', 'comp.lang.fortran',
			'comp.lang.functional', 'comp.lang.hermes', 'comp.lang.icon',
			'comp.lang.idl', 'comp.lang.idl-pvwave',
			'comp.lang.java.advocacy', 'comp.lang.java.announce',
			'comp.lang.java.beans', 'comp.lang.java.corba',
			'comp.lang.java.databases', 'comp.lang.java.gui',
			'comp.lang.java.help', 'comp.lang.java.machine',
			'comp.lang.java.programmer', 'comp.lang.java.security',
			'comp.lang.java.softwaretools', 'comp.lang.javascript',
			'comp.lang.labview', 'comp.lang.limbo', 'comp.lang.lisp',
			'comp.lang.lisp.franz', 'comp.lang.lisp.mcl',
			'comp.lang.lisp.x', 'comp.lang.logo', 'comp.lang.misc',
			'comp.lang.ml', 'comp.lang.modula2', 'comp.lang.modula3',
			'comp.lang.mumps', 'comp.lang.oberon', 'comp.lang.objective-c',
			'comp.lang.pascal.ansi-iso', 'comp.lang.pascal.borland',
			'comp.lang.pascal.delphi.advocacy',
			'comp.lang.pascal.delphi.announce',
			'comp.lang.pascal.delphi.components.misc',
			'comp.lang.pascal.delphi.components.usage',
			'comp.lang.pascal.delphi.components.writing',
			'comp.lang.pascal.delphi.databases',
			'comp.lang.pascal.delphi.misc', 'comp.lang.pascal.mac',
			'comp.lang.pascal.misc', 'comp.lang.perl.announce',
			'comp.lang.perl.misc', 'comp.lang.perl.moderated',
			'comp.lang.perl.modules', 'comp.lang.perl.tk', 'comp.lang.pl1',
			'comp.lang.php', 'comp.lang.pop', 'comp.lang.postscript',
			'comp.lang.prograph', 'comp.lang.prolog', 'comp.lang.python',
			'comp.lang.python.announce', 'comp.lang.rexx', 'comp.lang.ruby',
			'comp.lang.sather', 'comp.lang.scheme', 'comp.lang.scheme.c',
			'comp.lang.scheme.scsh', 'comp.lang.smalltalk', 'comp.lang.tcl',
			'comp.lang.tcl.announce', 'comp.lang.verilog', 'comp.lang.vhdl',
			'comp.lang.visual', 'comp.lang.vrml']

oldbasename='' ####### for comp.lang.* hierarchies

virgin=1
authors=[]
data=[]

########### main loop
for newsgroup in newsgroups:
	basename=join(newsgroup.split('.')[:3],'.')
	gr=s.group(newsgroup)
	############### flush data to data array, and empty author pool,
	############### if new basename detected, 
	############### and we've done at least one already.....
	if basename != oldbasename and not virgin:
		print "total users: ", len(authors)
		data.append([len(authors), oldbasename])
		authors=[]
	print 'group is', newsgroup
	print 'basename is', basename
	pool=s.xhdr('date','-') ####### give me all you've got on the server
	date_pool=[]
	for date in pool[1]:  ######## filter out all those not Dec 2002
	########### enter date below:
		if date[1].find('Dec 2002') != -1:
			date_pool.append(date[0])
	try:  ######## ignore if empty, try next newsgroup
		first=date_pool[0]
		last=date_pool[-1]
		image=first + '-' + last
	except:
		continue
	array=s.xhdr('from', image)	
	##############################
	for article in array[1]:
		author=article[1]
		if not author in authors:
			authors.append(author)
	########### output:
	oldbasename=basename
	virgin=0

##### final flush after exiting for loop:
print "total users: ", len(authors)
data.append([len(authors), oldbasename])

####### now we sort:
data.sort()
data.reverse()
for item in data:
	outfile.write("%s %s\n" % (item[1],item[0]))
outfile.close()

		





More information about the Python-list mailing list