jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/738510 )
Change subject: [IMPR] Add support for translated dates/times
......................................................................
[IMPR] Add support for translated dates/times
This implementation just combines date, year and time from pywikibot.date
lookup. It could be more precise if MonthFormat would have a day_years_format
entry but most of the current year_formats entries are default which just
append the year to the month.
Bug: T102174
Change-Id: I85bb7ed797696d647dd39d4ca744d9bd8bc5133a
---
M scripts/revertbot.py
1 file changed, 13 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index d7ab872..b5e63b4 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -43,8 +43,10 @@
from typing import Union
import pywikibot
+
from pywikibot import i18n
from pywikibot.bot import OptionHandler
+from pywikibot.date import format_date, formatYear
from pywikibot.exceptions import APIError, Error
from pywikibot.tools.formatter import color_format
@@ -92,6 +94,16 @@
"""Callback function."""
return 'top' in item
+ def local_timestamp(self, ts) -> str:
+ """Convert Timestamp to a localized timestamp string.
+
+ .. versionadded:: 7.0
+ """
+ year = formatYear(self.site.lang, ts.year)
+ date = format_date(ts.month, ts.day, self.site)
+ *_, time = str(ts).strip('Z').partition('T')
+ return ' '.join((date, year, time))
+
def revert(self, item) -> Union[str, bool]:
"""Revert a single item."""
page = pywikibot.Page(self.site, item['title'])
@@ -110,7 +122,7 @@
self.site, 'revertbot-revert',
{'revid': rev.revid,
'author': rev.user,
- 'timestamp': rev.timestamp})
+ 'timestamp': self.local_timestamp(rev.timestamp)})
if self.opt.comment:
comment += ': ' + self.opt.comment
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/738510
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I85bb7ed797696d647dd39d4ca744d9bd8bc5133a
Gerrit-Change-Number: 738510
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged