Revision: 7060
Author: alexsh
Date: 2009-07-14 12:12:17 +0000 (Tue, 14 Jul 2009)
Log Message:
-----------
family_check.py
*remove import output from wp (wikipedia is imported)
*set API data receive from self post to query.py.
Modified Paths:
--------------
trunk/pywikipedia/maintenance/family_check.py
Modified: trunk/pywikipedia/maintenance/family_check.py
===================================================================
--- trunk/pywikipedia/maintenance/family_check.py 2009-07-14 07:37:25 UTC (rev 7059)
+++ trunk/pywikipedia/maintenance/family_check.py 2009-07-14 12:12:17 UTC (rev 7060)
@@ -1,42 +1,33 @@
import sys
sys.path.append('..')
-import wikipedia, config
-from wikipedia import output
+import wikipedia, config, query
-import simplejson
-
def check_namespaces(site):
try:
if not site.apipath():
- output(u'Warning! %s has no apipath() defined!' % site)
+ wikipedia.output(u'Warning! %s has no apipath() defined!' % site)
return
except NotImplementedError:
# TODO: If use Special:Export to get XML file and parse details in <namespaces></namespaces>,
# we can get the namespace names without API.
- output(u'Warning! %s is not support API!' % site)
+ wikipedia.output(u'Warning! %s is not support API!' % site)
return
predata = { 'action': 'query',
'meta': 'siteinfo',
- 'siprop': 'namespaces',
- 'format': 'json'}
+ 'siprop': 'namespaces'}
try:
- response, json = site.postForm(site.apipath(), predata)
+ data = query.GetData(predata, site = site, useAPI = True)['query']['namespaces']
except wikipedia.ServerError, e:
- output(u'Warning! %s: %s' % (site, e))
+ wikipedia.output(u'Warning! %s: %s' % (site, e))
return
- try:
- data = simplejson.loads(json)
- except ValueError:
- output(u'Warning! %s is defined but does not exist!' % site)
- return
result = []
- for namespace in data['query']['namespaces'].itervalues():
+ for namespace in data.itervalues():
try:
defined_namespace = site.namespace(namespace['id'])
except KeyError:
- output(u'Warning! %s has no _default for namespace %s' % \
+ wikipedia.output(u'Warning! %s has no _default for namespace %s' % \
(site, namespace['id']))
defined_namespace = None
@@ -45,16 +36,16 @@
return result
def check_family(family):
- output(u'Checking namespaces for %s' % family.name)
+ wikipedia.output(u'Checking namespaces for %s' % family.name)
result = {}
for lang in family.langs:
if not family.obsolete.has_key(lang):
site = wikipedia.getSite(lang, family)
- output(u'Checking %s' % site)
+ wikipedia.output(u'Checking %s' % site)
namespaces = check_namespaces(site)
if namespaces:
for id, name, defined_namespace in namespaces:
- output(u'Namespace %s for %s is %s, %s is defined in family file.' % \
+ wikipedia.output(u'Namespace %s for %s is %s, %s is defined in family file.' % \
(id, site, name, defined_namespace))
result[lang] = namespaces
return result
@@ -64,8 +55,8 @@
wikipedia.handleArgs()
family = wikipedia.Family(wikipedia.default_family)
result = check_family(family)
- output(u'Writing raw Python dictionary to stdout.')
- output(u'Format is: (namespace_id, namespace_name, predefined_namespace)')
+ wikipedia.output(u'Writing raw Python dictionary to stdout.')
+ wikipedia.output(u'Format is: (namespace_id, namespace_name, predefined_namespace)')
print result
finally:
wikipedia.stopme()