http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10624
Revision: 10624
Author: xqt
Date: 2012-10-30 16:25:44 +0000 (Tue, 30 Oct 2012)
Log Message:
-----------
use config.maxretries per default for retries
Modified Paths:
--------------
trunk/pywikipedia/query.py
Modified: trunk/pywikipedia/query.py
===================================================================
--- trunk/pywikipedia/query.py 2012-10-28 11:48:28 UTC (rev 10623)
+++ trunk/pywikipedia/query.py 2012-10-30 16:25:44 UTC (rev 10624)
@@ -27,6 +27,7 @@
import time
import wikipedia as pywikibot
+import config
try:
#For Python 2.6 newer
import json
@@ -38,8 +39,8 @@
import simplejson as json
-def GetData(params, site=None, useAPI=True, retryCount=5, encodeTitle=True,
- sysop=False, back_response=False):
+def GetData(params, site=None, useAPI=True, retryCount=config.maxretries,
+ encodeTitle=True, sysop=False, back_response=False):
"""Get data from the query api, and convert it into a data object
"""
if ('action' in params) and pywikibot.simulate and \
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10622
Revision: 10622
Author: xqt
Date: 2012-10-28 10:40:09 +0000 (Sun, 28 Oct 2012)
Log Message:
-----------
leading colon implies main namespace instead of the default,
also if we have preleading family or site
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2012-10-28 09:27:21 UTC (rev 10621)
+++ trunk/pywikipedia/wikipedia.py 2012-10-28 10:40:09 UTC (rev 10622)
@@ -299,16 +299,14 @@
t = t.strip()
# Remove left-to-right and right-to-left markers.
t = t.replace(u'\u200e', '').replace(u'\u200f', '')
- # leading colon implies main namespace instead of the default
+
if t.startswith(':'):
t = t[1:]
- self._namespace = 0
+ prefix = True
else:
- self._namespace = defaultNamespace
+ prefix = False
+ self._namespace = defaultNamespace
- if not t:
- raise InvalidTitle(u"Invalid title '%s'" % title )
-
#
# This code was adapted from Title.php : secureAndSplit()
#
@@ -316,7 +314,16 @@
while True:
m = reNamespace.match(t)
if not m:
+ # leading colon implies main namespace instead of default
+ if t.startswith(':'):
+ t = t[1:]
+ self._namespace = 0
+ elif prefix:
+ self._namespace = 0
+ else:
+ self._namespace = defaultNamespace
break
+ prefix = False
p = m.group(1)
lowerNs = p.lower()
ns = self._site.getNamespaceIndex(lowerNs)
@@ -338,11 +345,6 @@
if t == '':
t = self._site.mediawiki_message('Mainpage')
- # If there's an initial colon after the interwiki, that also
- # resets the default namespace
- if t != '' and t[0] == ':':
- self._namespace = 0
- t = t[1:]
elif lowerNs in self._site.family.get_known_families(site = self._site):
if self._site.family.get_known_families(site = self._site)[lowerNs] == self._site.family.name:
t = m.group(2)
@@ -372,6 +374,9 @@
# then let the colon expression be part of the title.
break
+ if not t:
+ raise InvalidTitle(u"Invalid title '%s'" % title )
+
sectionStart = t.find(u'#')
# But maybe there are magic words like {{#time|}}
# TODO: recognize magic word and templates inside links
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10615
Revision: 10615
Author: amir
Date: 2012-10-25 22:02:28 +0000 (Thu, 25 Oct 2012)
Log Message:
-----------
page.get() now is working on wikidata. you can give title "Helium" not "Q321"
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2012-10-25 16:19:34 UTC (rev 10614)
+++ trunk/pywikipedia/wikipedia.py 2012-10-25 22:02:28 UTC (rev 10615)
@@ -752,6 +752,14 @@
'inprop': ['protection', 'subjectid'],
#'intoken': 'edit',
}
+ params1=params.copy()
+ if self.site().lang==u"wikidata":
+ params['action']='wbgetentities'
+ params['sites']='enwiki'
+ del params['prop']
+ del params['rvprop']
+ del params['rvlimit']
+ del params['inprop']
if oldid:
params['rvstartid'] = oldid
if expandtemplates:
@@ -762,6 +770,14 @@
textareaFound = False
# retrying loop is done by query.GetData
data = query.GetData(params, self.site(), sysop=sysop)
+ if self.site().lang==u"wikidata":
+ data['query']={'pages':data['entities']}
+ for pageid in data['entities'].keys():
+ if pageid=="-1":
+ continue #Means the page does not exist
+ params1['titles']="Q"+pageid
+ ndata=query.GetData(params1, self.site(), sysop=sysop)['query']['pages']
+ data['query']['pages'].update(ndata)
if 'error' in data:
raise RuntimeError("API query error: %s" % data)
if not 'pages' in data['query']: