jenkins-bot has submitted this change and it was merged.
Change subject: Bug 64833-Add page.userNameHuman as lastNonBotUser ......................................................................
Bug 64833-Add page.userNameHuman as lastNonBotUser
Site.isBot(): return True is username is a bot user on Site. Site.botusers(): returns an iterator to a dict containing users info. Page.lastNonBotUser(): returns the last human editor on the page.
Change-Id: I42c8e249072e7d2940f690a0c0ecb8ba2578677a --- M pywikibot/page.py M pywikibot/site.py 2 files changed, 50 insertions(+), 0 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 141224c..2de06c2 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -449,6 +449,30 @@ self.site.loadrevisions(self) return self._revisions[rev].anon
+ def lastNonBotUser(self): + """Return name or IP address of last human/non-bot user to edit page. + + Returns the most recent human editor out of the last revisions + If it was not able to retrieve a human user returns None. + If the edit was done by a bot which is no longer flagged as 'bot', + i.e. which is not returned by Site.botusers(), it will be returned + as a non-bot edit. + + """ + + if hasattr(self, '_lastNonBotUser'): + return self._lastNonBotUser + + self._lastNonBotUser = None + for vh in self.getVersionHistory(): + (revid, timestmp, username, comment) = vh[:4] + + if username and (not self.site.isBot(username)): + self._lastNonBotUser = username + break + + return self._lastNonBotUser + def editTime(self): """Return timestamp of last revision to page.
diff --git a/pywikibot/site.py b/pywikibot/site.py index ef20492..e6d6f7f 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -2058,6 +2058,32 @@ limit = number return self.allcategories(total=limit)
+ def isBot(self, username): + """Return True is username is a bot user. """ + + return username in [userdata['name'] for userdata in self.botusers()] + + def botusers(self, step=None, total=None): + """Iterate bot users. + + Iterated values are dicts containing 'name', 'userid', 'editcount', + 'registration', and 'groups' keys. 'groups' will be present only if + the user is a member of at least 1 group, and will be a list of + unicodes; all the other values are unicodes and should always be + present. + + """ + + if not hasattr(self, "_bots"): + self._bots = {} + + if not self._bots: + for item in self.allusers(group='bot', step=step, total=total): + self._bots.setdefault(item['name'], item) + + for value in self._bots.values(): + yield value + def allusers(self, start="!", prefix="", group=None, step=None, total=None): """Iterate registered users, ordered by username.