jenkins-bot has submitted this change and it was merged.
Change subject: Reimplement imageuncat's -recentchanges as a pagegenerators CLA ......................................................................
Reimplement imageuncat's -recentchanges as a pagegenerators CLA
Modify pagegenerators' -recentchanges in order to also implement imageuncat's corresponding parameter functionality. Add required test to pagegenerators_tests.
Deprecate -recentchanges in imageuncat, and redirect -recentchanges' code from imageuncat to pagegenerators.
Bug: T129193 Change-Id: I86251d22e9ef0e376e780093e9e53d69da7b6e0e --- M pywikibot/pagegenerators.py M scripts/imageuncat.py M tests/pagegenerators_tests.py 3 files changed, 62 insertions(+), 9 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 99a3b60..10fde98 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -31,6 +31,7 @@ import sys import time
+from datetime import timedelta from warnings import warn
import pywikibot @@ -181,7 +182,17 @@
-recentchanges Work on the pages with the most recent changes. If given as -recentchanges:x, will work on the x most recently - changed pages. + changed pages. If given as -recentchanges:offset,duration it will + work on pages changed from 'offset' minutes with 'duration' + minutes of timespan. + + By default, if no values follow -recentchanges, then we pass + -recentchanges:x where x = 60 + + Examples: + -recentchanges:20 will give the 20 most recently changed pages + -recentchanges:120,70 will give pages with 120 offset + minutes and 70 minutes of timespan
-unconnectedpages Work on the most recent unconnected pages to the Wikibase repository. Given as -unconnectedpages:x, will work on the @@ -674,11 +685,29 @@ gen = RandomPageGenerator(total=intNone(value), site=self.site, namespace=namespaces) elif arg == '-recentchanges': - value = int(value) if value else 60 + rcstart = None + rcend = None + params = value.split(',') + if len(params) == 2: + offset = float(params[0]) + duration = float(params[1]) + if offset < 0 or duration < 0: + raise ValueError('Negative valued parameters passed.') + elif len(params) > 2: + raise ValueError('More than two parameters passed.') + else: + value = int(value) if value else 60 + if len(params) == 2: + ts_time = self.site.server_time() + rcstart = ts_time + timedelta(minutes=-(offset + duration)) + rcend = ts_time + timedelta(minutes=-offset) gen = RecentChangesPageGenerator(namespaces=self.namespaces, - total=value, + start=rcstart, + end=rcend, site=self.site, + reverse=True, _filter_unique=self._filter_unique) + elif arg == '-liverecentchanges': gen = LiveRCPageGenerator(self.site, total=intNone(value)) elif arg == '-file': diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py index b63f4f6..38cdaf8 100755 --- a/scripts/imageuncat.py +++ b/scripts/imageuncat.py @@ -8,11 +8,14 @@ This script is working on the given site, so if the commons should be handled, the site commons should be given and not a Wikipedia or similar.
--yesterday Go through all uploads from yesterday. +-yesterday Go through all uploads from yesterday. (Deprecated here, moved + to pagegenerators)
--recentchanges Go through the changes made between 120 minutes and 70 - minutes ago. (This overrides the '-recentchanges' default - generator) +-recentchanges Go through the changes made from 'offset' minutes with 'duration' + minutes of timespan. It must be given two arguments as + '-recentchanges:offset,duration' + + Default value of offset is 120, and that of duration is 70
¶ms; """ @@ -32,7 +35,9 @@ import pywikibot from pywikibot.exceptions import ArgumentDeprecationWarning from pywikibot import pagegenerators -from pywikibot.tools import issue_deprecation_warning +from pywikibot.tools import ( + issue_deprecation_warning, deprecated +)
docuReplacements = { '¶ms;': pagegenerators.parameterHelp, @@ -1267,6 +1272,7 @@ yield logentry.page()
+@deprecated('RecentChangesPageGenerator') def recentChanges(site=None, delay=0, block=70): """ Return a pagegenerator containing all the images edited in a certain timespan. @@ -1371,6 +1377,9 @@ genFactory = pagegenerators.GeneratorFactory(site)
for arg in local_args: + param_arg, sep, param_value = arg.partition(':') + if param_value == '': + param_value = None if arg.startswith('-yesterday'): generator = uploadedYesterday(site) issue_deprecation_warning( @@ -1378,7 +1387,13 @@ '-logevents:"upload,,YYYYMMDD,YYYYMMDD"', 2, ArgumentDeprecationWarning) elif arg.startswith('-recentchanges'): - generator = recentChanges(site=site, delay=120) + if param_value is None: + arg = arg + ':120,70' + issue_deprecation_warning( + '-recentchanges', + '-recentchanges:offset,duration', + 2, ArgumentDeprecationWarning) + genFactory.handleArg(arg) else: genFactory.handleArg(arg)
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 6c70194..150574d 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -803,6 +803,15 @@ self.assertIsNotNone(gen) self.assertPagesInNamespaces(gen, 1)
+ def test_recentchanges_timespan(self): + """Test recentchanges generator with offset and duration params.""" + gf = pagegenerators.GeneratorFactory(site=self.site) + gf.handleArg('-recentchanges:120,70') + gen = gf.getCombinedGenerator() + self.assertIsNotNone(gen) + self.assertRaises(ValueError, gf.handleArg, '-recentchanges:3,2,1') + self.assertRaises(ValueError, gf.handleArg, '-recentchanges:-10,20') + def test_recentchanges_ns_default(self): """Test recentchanges generator.""" gf = pagegenerators.GeneratorFactory(site=self.site)
pywikibot-commits@lists.wikimedia.org