get list of a newsgroups from commandline
Julien ÉLIE
julien at trigofacile.com
Sun Jun 8 17:12:45 UTC 2008
Hi (again),
> how to get a list of local newsgroups on INN from commandline
You might want to have a look at:
getlist
or even:
cat /var/lib/news/active
if you are on the news server itself.
> i need to write a script , which will check if newsgroup exist, if not it
> will create a new one.
To create a new group:
ctlinnd newgroup your.group y
ctlinnd newgroup your.moderated.group m
In case it can be of help, here is a script I wrote for Russ Allbery
some time ago. You might perhaps find it useful for your need.
Just call:
./nntp2checkgroups.py news.server.com
And you have the list of the groups.
Here, it will print them but as you know well Python, you will be able
to easily hack it to check whether group[0] is the group you are looking
for during the main loop.
##########################################################################
#!/usr/bin/python
# -*- coding: latin1 -*-
#
# nntp2checkgroups.py news.server [hierarchy]
import nntplib
import sys
if len(sys.argv) == 1:
sys.exit('The name of the news server is missing.')
if len(sys.argv) == 3:
hierarchy = sys.argv[2]
else:
hierarchy = ''
news_server = nntplib.NNTP(sys.argv[1])
list = news_server.list()
descriptions = news_server.descriptions('*')
news_server.quit()
groups = dict()
for group in [g for g in list[1] if g[0].startswith(hierarchy)]:
if group[3] == 'y':
groups[group[0]] = 'No description.'
else:
groups[group[0]] = 'No description. (Moderated)'
for description in [d for d in descriptions[1] if groups.has_key(d[0])]:
if description[1] != '':
if groups[description[0]].endswith(' (Moderated)'):
if not description[1].endswith(' (Moderated)'):
groups[description[0]] = description[1] + ' (Moderated)'
else:
groups[description[0]] = description[1]
else:
groups[description[0]] = description[1]
keys = groups.keys()
keys.sort()
for group in keys:
if len(group) < 8:
print group + '\t\t\t' + groups[group]
elif len(group) < 16:
print group + '\t\t' + groups[group]
else:
print group + '\t' + groups[group]
##########################################################################
--
Julien ÉLIE
« Summum ius, summa iniuria. » (Cicéron)
More information about the inn-workers
mailing list