Purple exclamation mark.svg Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.

Red exclamation mark.svg UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.

Python:Mwclient/ init .py

From Botwiki
Jump to: navigation, search
import page, errors
 
class Categories(object):
	def __init__(self, mediawiki):
		self.mediawiki = mediawiki
	def __getitem__(self, key):
		return Category(self.mediawiki, key)
 
class Category(object):
	def __init__(self, mediawiki, name):
		self.mediawiki = mediawiki
		self.name = name
 
		self.key = ''
		self.load_chunck()
 
	def load_chunk(self):
		info = self.mediawiki.query('category|permissions', cptitle = self.name, 
			cplimit = '500', cpfrom = self.key)
		if 'error' in info: raise RuntimeError, info['error']
 
		self._iterator = info.get('pages', {}).itervalues()
		self.key = info.get('query', {}).get('category', {}).get('next')
 
	def __iter__(self):
		return self
 
	def next(self):
		try:
			item = self._iterator.next()
			return page.Page(self.mediawiki, item['title'], (item, ))
		except StopIteration:
			if self.key is None: raise StopIteration		
			self.load_chunck()
			return self.next()
Personal tools
Share