http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11388
Revision: 11388 Author: amir Date: 2013-04-19 12:53:14 +0000 (Fri, 19 Apr 2013) Log Message: ----------- APIfying blocksearch_address
Modified Paths: -------------- trunk/pywikipedia/userlib.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/userlib.py =================================================================== --- trunk/pywikipedia/userlib.py 2013-04-18 23:10:12 UTC (rev 11387) +++ trunk/pywikipedia/userlib.py 2013-04-19 12:53:14 UTC (rev 11388) @@ -113,7 +113,7 @@ return self.registrationTime(force) != -1
def isAnonymous(self): - return ip_regexp.match(self.username) is not None + return ip_regexp.match(self.username.split("/")[0]) is not None
def __str__(self): return (u'%s:%s' @@ -522,13 +522,17 @@
def _getBlockID(self): pywikibot.output(u"Getting block id for [[User:%s]]..." % self.name()) - address = self.site().blocksearch_address(self.name()) - data = self.site().getUrl(address) - bIDre = re.search(r'action=unblock&id=(\d+)', data) - if not bIDre: + if self.isAnonymous(): + usertype="ip" + else: + usertype="users" + data = self.site().blocksearch_address(self.name(),usertype) + try: + bIDre = data[1]["query"]["blocks"][0]["id"] + except KeyError: pywikibot.output(data) raise BlockIDError - return bIDre.group(1) + return bIDre
def _unblock(self, blockID, reason): pywikibot.output(u"Unblocking [[User:%s]]..." % self.name())
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2013-04-18 23:10:12 UTC (rev 11387) +++ trunk/pywikipedia/wikipedia.py 2013-04-19 12:53:14 UTC (rev 11388) @@ -8296,9 +8296,14 @@ """Return path to unblock an IP address.""" return self.family.unblock_address(self.lang)
- def blocksearch_address(self, s): + def blocksearch_address(self, s, usertype): """Return path to search for blocks on IP address 's'.""" - return self.family.blocksearch_address(self.lang, s) + params = { + 'bk%s' % usertype : s, + 'action' : 'query', + 'list' : 'blocks', + } + return query.GetData(params, self, back_response=True)
def linksearch_address(self, s, limit=500, offset=0): """Return path to Special:Linksearch for target 's'."""