This change is incorrect. Categories() should return Page objects, not
Unicode objects. Could you please fix this?
Maarten
Op 28-4-2010 22:29,
shizhao@svn.wikimedia.org
schreef:
Revision: 8136
Author: shizhao
Date: 2010-04-28 20:29:31 +0000 (Wed, 28 Apr 2010)
Log Message:
-----------
categories() new add API query.
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2010-04-28 14:33:06 UTC (rev
8135)
+++ trunk/pywikipedia/wikipedia.py 2010-04-28 20:29:31 UTC (rev
8136)
@@ -2173,12 +2173,50 @@
category links in the page text.
"""
- try:
- category_links_to_return =
getCategoryLinks(self.get(get_redirect=get_redirect), self.site())
- except NoPage:
- category_links_to_return = []
- return category_links_to_return
+# New add API query.
+#
api.php?action=query&prop=categories&titles=Albert%20Einstein
+
+#
+ if not self.site().has_api():
+ try:
+ category_links_to_return =
getCategoryLinks(self.get(get_redirect=get_redirect), self.site())
+ except NoPage:
+ category_links_to_return = []
+ return category_links_to_return
+
+ params = {
+ 'action': 'query',
+ 'prop' : 'categories',
+ 'titles' : self.title(),
+ }
+ if not self.site().isAllowed('apihighlimits') and
config.special_page_limit> 500:
+ params['cllimit'] = 500
+
+
+ allDone = False
+ cats=[]
+ while not allDone:
+ output(u'Getting categories in %s via API...' %
self.aslink())
+
+ datas = query.GetData(params, self.site())
+ data=datas['query']['pages'].values()[0]
+ if "categories" in data:
+ for c in data['categories']:
+ cats.append(c['title'])
+# if len(data) == 2:
+# data = data[0] + data[1]
+# else:
+# data = data[0]
+
+ if 'query-continue' in datas:
+ if 'categories' in datas['query-continue']:
+ params['clcontinue'] =
datas['query-continue']['categories']['clcontinue']
+
+ else:
+ allDone = True
+ return cats
+
def __cmp__(self, other):
"""Test for equality and inequality of Page objects"""
if not isinstance(other, Page):
_______________________________________________
Pywikipedia-svn mailing list
Pywikipedia-svn@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn
---------- Forwarded message ----------
From:
pywikipedia-svn-request@lists.wikimedia.org
To:
Date:
Subject: confirm 5757ba7a08bb8766eda2b6838461d7dd08516048
If you reply to this message, keeping the Subject: header intact,
Mailman will discard the held message. Do this if the message is
spam. If you reply to this message and include an Approved: header
with the list password in it, the message will be approved for posting
to the list. The Approved: header can also appear in the first line
of the body of the reply.