def do_edit(): result = self.site.api('edit', title=self.name, text=text, summary=summary, token=self.get_token('edit'), **data) if result['edit'].get('result').lower() == 'failure': raise errors.EditError(self, result['edit']) return result
def save(self, text=u'', summary=u'', minor=False, bot=True): if not self.site.logged_in and self.site.force_login: # Should we really check for this? raise errors.LoginError(self.site) if self.site.blocked: raise errors.UserBlocked(self.site.blocked) if not self.can('edit'): raise errors.ProtectedPageError(self) if not text: text = self.text if not self.site.writeapi: return OldPage.save(self, text=text, summary=summary, minor=False) data = {} if minor: data['minor'] = '1' if not minor: data['notminor'] = '1' if self.edit_time: data['basetimestamp'] = time.strftime('%Y%m%d%H%M%S', self.edit_time) if bot: data['bot'] = '1' try: result = self.site.api('edit', title=self.name, text=text, summary=summary, token=self.get_token('edit'), **data) if result['edit'].get('result').lower() == 'failure': raise errors.EditError(self, result['edit']) except errors.APIError, e: if e.code == 'editconflict': raise errors.EditError(self, text, summary, e.info) elif e.code in ('protectedtitle', 'cantcreate', 'cantcreate-anon', 'noimageredirect-anon', 'noimageredirect', 'noedit-anon', 'noedit'): raise errors.ProtectedPageError(self, e.code, e.info) else: raise
def move(self, new_title, reason='', move_talk=True): postdata = { 'wpNewTitle': new_title, 'wpOldTitle': self.name, 'wpReason': reason, 'wpMove': '1', 'wpEditToken': self.get_token('move') } if move_talk: postdata['wpMovetalk'] = '1' postdata['title'] = 'Special:Movepage' page_data = self.site.raw_index('submit', **data) page = EditPage('movepage') page.feed(page_data.decode('utf-8', 'ignore')) page.close() if 'wpEditToken' in page.data: raise errors.EditError(page.title, postdata)