jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1228309?usp=email )

Change subject: Implement site generator for AbuseLog and User.last_activity 
method
......................................................................

Implement site generator for AbuseLog and User.last_activity method

Bug: T396298
Bug: T396297
Change-Id: I4ceaf9c9ac0d5cda0d44f88ee88211a40c449acb
---
M pywikibot/page/_user.py
M pywikibot/site/_generators.py
2 files changed, 68 insertions(+), 4 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/page/_user.py b/pywikibot/page/_user.py
index 893a637..59470fe 100644
--- a/pywikibot/page/_user.py
+++ b/pywikibot/page/_user.py
@@ -333,7 +333,7 @@
         """
         self.site.unblockuser(self, reason)

-    def logevents(self, **kwargs):
+    def logevents(self, **kwargs) -> Generator[pywikibot.logentries.LogEntry]:
         """Yield user activities.

         :keyword str logtype: Only iterate entries of this type (see
@@ -357,14 +357,46 @@
         return self.site.logevents(user=self.username, **kwargs)

     @property
-    def last_event(self):
-        """Return last user activity.
+    def last_event(self) -> pywikibot.logentries.LogEntry | None:
+        """Return last user log event.

         :return: Last user log entry
-        :rtype: LogEntry or None
         """
         return next(self.logevents(total=1), None)

+    @property
+    def last_activity(self) -> pywikibot.Timestamp | None:
+        """Return timestamp of last user activity.
+
+        This includes the last log event, last edit, last deleted
+        contribution, and last abuse log entry.
+
+        .. versionadded:: 11.0
+
+        :return: Timestamp of last user activity
+        """
+        last = set()
+
+        if last_event := self.last_event:
+            last.add(last_event.timestamp())
+
+        if last_edit := self.last_edit:
+            last.add(last_edit[2])
+
+        if last_deleted_contrib := self.deleted_contributions(total=1):
+            last.add(next(last_deleted_contrib)[1]['timestamp'])
+
+        if last_abuse_log := self.site.abuselog(
+            user=self.username, total=1, aflprop='timestamp'
+        ):
+            last.add(
+                pywikibot.Timestamp.fromISOformat(
+                    next(last_abuse_log)['timestamp']
+                )
+            )
+
+        return max(last) if last else None
+
     def contributions(
         self,
         total: int | None = 500,
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index f5e9fff..1fc554a 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -1382,6 +1382,38 @@

         return legen

+    def abuselog(self,
+                 user: str | None = None,
+                 *,
+                 start: str | pywikibot.Timestamp | None = None,
+                 end: str | pywikibot.Timestamp | None = None,
+                 reverse: bool = False,
+                 total: int | None = None,
+                 **kwargs) -> Generator[dict[str, Any]]:
+        """Yield entries from Special:AbuseLog.
+
+        .. versionadded:: 11.0
+
+        .. seealso::
+           :api:`Abuselog`
+
+        :param user: Only iterate entries that match this user name
+        :param start: Only iterate entries from and after this Timestamp
+        :param end: Only iterate entries up to and through this Timestamp
+        :param reverse: If True, iterate oldest entries first (default:
+            newest)
+        :param total: Maximum number of events to iterate
+        """
+        if start and end:
+            self.assert_valid_iter_params('abuselog', start, end, reverse)
+
+        gen = self._generator(api.ListGenerator, type_arg='abuselog',
+                              afluser=user, total=total,
+                              aflstart=start, aflend=end,
+                              afldir=('newer' if reverse else 'older'),
+                              **kwargs)
+        return gen
+
     def recentchanges(
         self,
         *,

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1228309?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4ceaf9c9ac0d5cda0d44f88ee88211a40c449acb
Gerrit-Change-Number: 1228309
Gerrit-PatchSet: 4
Gerrit-Owner: Louperivois <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to