jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/816323 )

Change subject: [BUGFIX] replace archive pattern fields to string conversion
......................................................................

[BUGFIX] replace archive pattern fields to string conversion

use string conversion format fields to support non latin numbers
introduced with https://gerrit.wikimedia.org/r/c/pywikibot/core/+/163213

Bug: T313692
Change-Id: I205b8b86964887d6af184ecf058d4e50d5ed6fb3
---
M scripts/archivebot.py
1 file changed, 33 insertions(+), 16 deletions(-)

Approvals:
  PotsdamLamb: Looks good to me, but someone else must approve
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 4ab18e6..ecc33d6 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -54,16 +54,16 @@

 Variables below can be used in the value for "archive" in the template above:

-%(counter)d          the current value of the counter
-%(year)d             year of the thread being archived
-%(isoyear)d          ISO year of the thread being archived
-%(isoweek)d          ISO week number of the thread being archived
-%(semester)d         semester term of the year of the thread being archived
-%(quarter)d          quarter of the year of the thread being archived
-%(month)d            month (as a number 1-12) of the thread being archived
+%(counter)s          the current value of the counter
+%(year)s             year of the thread being archived
+%(isoyear)s          ISO year of the thread being archived
+%(isoweek)s          ISO week number of the thread being archived
+%(semester)s         semester term of the year of the thread being archived
+%(quarter)s          quarter of the year of the thread being archived
+%(month)s            month (as a number 1-12) of the thread being archived
 %(monthname)s        localized name of the month above
 %(monthnameshort)s   first three letters of the name above
-%(week)d             week number of the thread being archived
+%(week)s             week number of the thread being archived

 The ISO calendar starts with the Monday of the week which has at least four
 days in the new Gregorian calendar. If January 1st is between Monday and
@@ -86,6 +86,10 @@
   -namespace:NS   only archive pages from a given namespace
   -page:PAGE      archive a single PAGE, default ns is a user talk page
   -salt:SALT      specify salt
+
+.. versionchanged:: 7.5.1
+   string presentation type should be used for "archive" variable in the
+   template to support non latin values
 """
 #
 # (C) Pywikibot team, 2006-2022
@@ -434,7 +438,6 @@
             self.maxsize = 2096128  # 2 MB - 1 KB gap

         self.page = DiscussionPage(page, self)
-        self.load_config()
         self.comment_params = {
             'from': self.page.title(),
         }
@@ -444,6 +447,7 @@
         self.month_num2orig_names = {}
         for n, (long, short) in enumerate(self.site.months_names, start=1):
             self.month_num2orig_names[n] = {'long': long, 'short': short}
+        self.load_config()

     def get_attr(self, attr, default='') -> Any:
         """Get an archiver attribute."""
@@ -480,25 +484,38 @@
         return self.get_attr('key') == hexdigest

     def load_config(self) -> None:
-        """Load and validate archiver template."""
-        pywikibot.output('Looking for: {{{{{}}}}} in {}'.format(
-            self.tpl.title(), self.page))
+        """Load and validate archiver template.
+
+        .. versionchanged:: 7.5.1
+           replace archive pattern fields to string conversion
+        """
+        pywikibot.info('Looking for: {{{{{}}}}} in {}'
+                       .format(self.tpl.title(), self.page))
+
+        fields = self.get_params(self.now, 0).keys()  # dummy parameters
+        pattern = re.compile(r'%(\((?:{})\))d'.format('|'.join(fields)))
         for tpl, params in self.page.raw_extracted_templates:
             try:  # Check tpl name before comparing; it might be invalid.
                 tpl_page = pywikibot.Page(self.site, tpl, ns=10)
                 tpl_page.title()
             except Error:
                 continue
+
             if tpl_page == self.tpl:
                 for item, value in params.items():
+                    # convert archive pattern fields to string
+                    # to support non latin digits
+                    if item == 'archive':
+                        value = pattern.sub(r'%\1s', value)
                     self.set_attr(item.strip(), value.strip())
                 break
         else:
             raise MissingConfigError('Missing or malformed template')
-        if not self.get_attr('algo', ''):
-            raise MissingConfigError('Missing argument "algo" in template')
-        if not self.get_attr('archive', ''):
-            raise MissingConfigError('Missing argument "archive" in template')
+
+        for field in ('algo', 'archive'):
+            if not self.get_attr(field, ''):
+                raise MissingConfigError('Missing argument {!r} in template'
+                                         .format(field))

     def should_archive_thread(self, thread: DiscussionThread
                               ) -> Optional[ShouldArchive]:

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/816323
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: I205b8b86964887d6af184ecf058d4e50d5ed6fb3
Gerrit-Change-Number: 816323
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: PotsdamLamb
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to