CLP stats: last 500 posts

Peter Otten __peter__ at web.de
Sat Dec 10 13:06:47 EST 2016


Wildman via Python-list wrote:

> On Fri, 09 Dec 2016 16:07:16 -0500, DFS wrote:
> 
>> code (py2.7)
>> --------------------------------------------------------------
>> import sys as y,nntplib as t,datetime as d
>> s='<news server>'
>> g=y.argv[1]
>> n=t.NNTP(s,119,'<usr>','<pw>')
>> r,a,b,e,gn=n.group(g)
>> def printStat(st,hd,rg):
>> r,d=n.xhdr(st,'%s-%s'%rg)
>> p=[]
>> for i in range(len(d)):
>> v=d[i][1]
>> if st=='Subject':v=v[4:] if v[:3]=='Re:' else v
>> p.append(v)
>> x=[(i,p.count(i)) for i in set(p)]
>> x.sort(key=lambda s:(-s[1],s[0].lower()))
>> print('Posts  %s %s'%(len(set(p)),hd))
>> for v in x: print(' %s     %s'%(v[1],v[0]))
>> print
>> print 'As of '+d.datetime.now().strftime("%I:%M%p %B %d, %Y") + '\n'
>> m=(int(e)-int(y.argv[3])+1,int(e))
>> printStat("From","Posters",m)
>> printStat("Subject","Subjects",m)
>> printStat("User-Agent","User-Agents",m)
>> n.quit()
>> --------------------------------------------------------------
>> 
>> usage on Windows:
>> $ python stats.py group last N
>> $ python stats.py comp.lang.python last 500
> 
> Do you happen to have a translation of the code that will
> run on Linux?
> 
> $ ./nntp.py comp.lang.python last 500
> Traceback (most recent call last):
>   File "./nntp.py", line 7, in <module>
>     n=t.NNTP(s,119,'<usr>','<pw>')
>   File "/usr/lib/python2.7/nntplib.py", line 119, in __init__
>     self.sock = socket.create_connection((host, port))
>   File "/usr/lib/python2.7/socket.py", line 553, in create_connection
>     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
> socket.gaierror: [Errno -2] Name or service not known
> 

That's not a Linux problem. For the code to run in 

>> s='<news server>'

>> n=t.NNTP(s,119,'<usr>','<pw>')

you need to replace the '<...>' strings with a real news server, user, and 
password. If you use Gmane no password is required:

n = t.NNTP("news.gmane.org")

However, they use a different name for the "comp.lang.python" group, so you 
have to modify the command line accordingly:

$ python stats.py gmane.comp.python.general last 500




More information about the Python-list mailing list