jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1155115?usp=email )
Change subject: IMPR: Use wikidata items for archive header templates ......................................................................
IMPR: Use wikidata items for archive header templates
Bug: T396399 Change-Id: I1fe3b337b70913602e43e37abcdcd80021deed5f --- M scripts/archivebot.py 1 file changed, 20 insertions(+), 4 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py index 9231ed1..4a2c26b 100755 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -187,6 +187,9 @@ from pywikibot.tools.threading import BoundedPoolExecutor
+ARCHIVE_HEADER = 'Q6068612', 'Q6723402' + + class ArchiveBotSiteConfigError(Error):
"""There is an error originated by archivebot's on-site configuration.""" @@ -390,6 +393,21 @@ return ts1 return max(ts1, ts2)
+ def get_header_template(self) -> str: + """Get localized archive header template. + + .. versionadded:: 10.2 + + :raises NotImplementedError: Archive header is not localized + """ + for item in ARCHIVE_HEADER: + tpl = self.site.page_from_repository(item) + if tpl: + return f'{{{{{tpl.title(with_ns=False)}}}}}' + + raise NotImplementedError( + 'Archive header is not localized on your site') + def load_page(self) -> None: """Load the page to be archived and break it up into threads.
@@ -402,13 +420,11 @@ self.header = '' self.threads = [] self.archives = {} - try: text = self.get() except NoPageError: - self.header = self.archiver.get_attr( - 'archiveheader', - i18n.twtranslate(self.site.code, 'archivebot-archiveheader')) + self.header = self.archiver.get_attr('archiveheader', + self.get_header_template()) if self.params: self.header = self.header % self.params return
pywikibot-commits@lists.wikimedia.org