jenkins-bot has submitted this change and it was merged.
Change subject: Add site.months_names(): get months names in original language ......................................................................
Add site.months_names(): get months names in original language
convenience method where original language in needed (e.g. archivebot.py)
Change-Id: Ic4bd23bb5b06400effdbb4990935576b6aaa7da5 --- M pywikibot/site.py M tests/site_tests.py 2 files changed, 26 insertions(+), 0 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 3048834..17518d6 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1037,6 +1037,30 @@ except KeyError: return False
+ @property + def months_names(self): + """Return a zero-indexed list of (month name, abbreviation) tuples, + ordered by month in calendar, in original site language. + + """ + if hasattr(self, "_months_names"): + return self._months_names + + months_long = ['january', 'february', 'march', + 'april', 'may_long', 'june', + 'july', 'august', 'september', + 'october', 'november', 'december'] + months_short = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', + 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] + + months = self.mediawiki_messages(months_long + months_short) + + self._months_names = [] + for m_l, m_s in zip(months_long, months_short): + self._months_names.append((months[m_l], months[m_s])) + + return self._months_names + def getcurrenttimestamp(self): """Return server time, {{CURRENTTIMESTAMP}}, as a string.
diff --git a/tests/site_tests.py b/tests/site_tests.py index 9276a53..f151cb1 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -166,6 +166,8 @@ self.assertType(ver, tuple) self.assertTrue(all(isinstance(ver[i], int) for i in (0, 1))) self.assertType(ver[2], basestring) + self.assertType(mysite.months_names, list) + self.assertEqual(mysite.months_names[4], (u'May', u'May'))
def testPageMethods(self): """Test ApiSite methods for getting page-specific info"""
pywikibot-commits@lists.wikimedia.org