Page MenuHomePhabricator

pywikibot: -random Not generating a default of 10 pages
Closed, DuplicatePublic

Description

In the docs it is mentioned that -random without any parameters should give 10 pages.

-random Work on random pages returned by [[Special:Random]]. Can also be given as "-random:n" where n is the number of pages to be returned, otherwise the default is 10 pages.

-randomredirect Work on random redirect pages returned by [[Special:RandomRedirect]]. Can also be given as "-randomredirect:n" where n is the number of pages to be returned, else 10 pages are returned.

But in reality it gives infinite pages.

Example:

$ python ../pywikibot-core/pwb.py download.py -ns:File -random
Retrieving 50 pages from commons:commons.
File:Wallpaper group-p4-1.jpg
File:Volvo740.jpg
File:Stabsmusikkorps.png
### And many more files ###

Retrieving 50 pages from commons:commons.
File:Gardenology.org-IMG 7300 hunt09jun.jpg
File:Heard-Lakeman House, Ipswich MA.jpg
File:PL Eliza Orzeszkowa-Z różnych sfer t.1,2 534.jpeg
File:Optasani OT.vechea bis lemn.ochi de fereastra.jpg
### And many more files ###

Retrieving 50 pages from commons:commons.
etc. ...

Event Timeline

This seems to happen because the kwarg uses:

gen = RandomPageGenerator(total=intNone(value), site=self.site,
                          namespaces=namespaces)

and the default value of 10 is given in the function like:

def RandomPageGenerator(total=10, site=None, namespaces=None):

Hence, the value of total is set to None if it is not given. It should actually be set to 10.

You'll need to use git blame to find why it is intNone(value).

Yup; probably best to fix it in the same changeset as T134720, esp. since it is adding unittests.

Alright then, merging this into that task