jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/995204?usp=email )
Change subject: [IMPR] Print bot execution time with days, hours, minutes and seconds ......................................................................
[IMPR] Print bot execution time with days, hours, minutes and seconds
Change-Id: I0bd14f03799863b0b718f5ee9e676f9281af4b60 --- M pywikibot/bot.py 1 file changed, 18 insertions(+), 8 deletions(-)
Approvals: jenkins-bot: Verified Matěj Suchánek: Looks good to me, approved
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 3121ebc..8707e8a 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -57,7 +57,7 @@ ``put_current`` is used. """ # -# (C) Pywikibot team, 2008-2023 +# (C) Pywikibot team, 2008-2024 # # Distributed under the terms of the MIT license. # @@ -1507,6 +1507,8 @@
.. versionchanged:: 7.3 Statistics are printed for all entries in :attr:`counter` + .. versionchanged:: 9.0 + Print execution time with days, hours, minutes and seconds. """ self.teardown() if hasattr(self, '_start_ts'): @@ -1523,13 +1525,12 @@ if hasattr(self, '_start_ts'): write_delta = pywikibot.Timestamp.now() - self._start_ts write_seconds = int(write_delta.total_seconds()) - if write_delta.days: - pywikibot.info( - 'Execution time: {d.days} days, {d.seconds} seconds' - .format(d=write_delta)) - else: - pywikibot.info( - f'Execution time: {write_delta.seconds} seconds') + hours, remainder = divmod(write_delta.seconds, 3600) + parts = write_delta.days, hours, *divmod(remainder, 60) + units = ('days', 'hours', 'minutes', 'seconds') + used = ', '.join(f'{value} {unit}' + for value, unit in zip(parts, units) if value) + pywikibot.info('Execution time: ' + used)
if self.counter['read']: pywikibot.info('Read operation time: {:.1f} seconds'
pywikibot-commits@lists.wikimedia.org