jenkins-bot has submitted this change and it was merged.

Change subject: archivebot: conformance to translate() and additional shorthands
......................................................................


archivebot: conformance to translate() and additional shorthands

Use dict as the argument for translate().
Additional shorthand notations for "years" and "weeks".

Change-Id: I1ef93cf16f0345ab858532e7a9c2063c76c554c4
---
M scripts/archivebot.py
1 file changed, 17 insertions(+), 7 deletions(-)

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



diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index d87e72c..5c925b6 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -155,12 +155,16 @@
     Translates a duration written in the shorthand notation (ex. "24h", "7d")
     into an expression in the local language of the wiki ("24 hours", "7 
days").
     """
-    if string[-1] == 'd':
-        template = site.mediawiki_message('Days')
-    elif string[-1] == 'h':
+    if string[-1] == 'h':
         template = site.mediawiki_message('Hours')
+    elif string[-1] == 'd':
+        template = site.mediawiki_message('Days')
+    elif string[-1] == 'w':
+        template = site.mediawiki_message('Weeks')
+    elif string[-1] == 'y':
+        template = site.mediawiki_message('Years')
     if template:
-        exp = i18n.translate(site.code, template, int(string[:-1]))
+        exp = i18n.translate(site.code, template, {'$1': int(string[:-1])})
         return to_local_digits(exp.replace('$1', string[:-1]), site.code)
     else:
         return to_local_digits(string, site.code)
@@ -173,12 +177,18 @@
     Accepts a string defining a time period:
     7d - 7 days
     36h - 36 hours
+    2w - 2 weeks (14 days)
+    1y - 366 days # to be on the safe side
     Returns the corresponding timedelta object.
     """
-    if string.endswith('d'):
-        return datetime.timedelta(days=int(string[:-1]))
-    elif string.endswith('h'):
+    if string.endswith('h'):
         return datetime.timedelta(hours=int(string[:-1]))
+    elif string.endswith('d'):
+        return datetime.timedelta(days=int(string[:-1]))
+    elif string.endswith('w'):
+        return datetime.timedelta(weeks=int(string[:-1]))
+    elif string.endswith('y'):
+        return datetime.timedelta(days=int(string[:-1]) * 366)
     else:
         return datetime.timedelta(seconds=int(string))
 

-- 
To view, visit https://gerrit.wikimedia.org/r/265222
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1ef93cf16f0345ab858532e7a9c2063c76c554c4
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Whym <w...@whym.org>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Whym <w...@whym.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
Pywikibot-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to