Page MenuHomePhabricator

Pywikibot: -random gives TypeError
Closed, ResolvedPublic

Description

I made a very simple script which simply prints the URL of a file. It throws a typeerror when the PageGenerator is being created.

#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import os

import pywikibot
from pywikibot import pagegenerators


def download(page):
    url = os.path.split(page.fileUrl())
    print(url)


def main(*args):
    generator = None
    local_args = pywikibot.handle_args(args)
    site = pywikibot.Site('commons', 'commons')
    genFactory = pagegenerators.GeneratorFactory(site)
    for arg in local_args:
        genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator(gen=generator)
    if not generator:
        pywikibot.bot.suggest_help(missing_generator=True)
    else:
        pregenerator = pagegenerators.PreloadingGenerator(generator)
        site.login()
        for page in pregenerator:
            if page.exists() and not page.isRedirectPage():
                download(page)
            pywikibot.output("")

if __name__ == "__main__":
    main()

This gives a TypeError when I try to use the RandomPageGenerator

$ python ../pywikibot-core/pwb.py download.py -namespaces:File -random:3
Traceback (most recent call last):
  File "../pywikibot-core/pwb.py", line 256, in <module>
    if not main():
  File "../pywikibot-core/pwb.py", line 250, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "../pywikibot-core/pwb.py", line 121, in run_python_file
    main_mod.__dict__)
  File "download.py", line 37, in <module>
    main()
  File "download.py", line 23, in main
    genFactory.handleArg(arg)
  File "/home/ajk/Documents/wiki/pywikibot-core/pywikibot/pagegenerators.py", line 688, in handleArg
    namespace=namespaces)
  File "/home/ajk/Documents/wiki/pywikibot-core/pywikibot/tools/__init__.py", line 1414, in wrapper
    return obj(*__args, **__kw)
TypeError: RandomPageGenerator() got an unexpected keyword argument 'namespace'
<type 'exceptions.TypeError'>
CRITICAL: Closing network session.

Event Timeline

AbdealiJK created this task.May 9 2016, 5:45 AM
Restricted Application added subscribers: pywikibot-bugs-list, Zppix, Aklapper. · View Herald TranscriptMay 9 2016, 5:45 AM
AbdealiJK claimed this task.May 9 2016, 5:58 AM
Mpaa added a subscriber: Mpaa.May 9 2016, 8:15 PM
This comment was removed by Mpaa.

Change 287884 had a related patch set uploaded (by AbdealiJK):
pagegenerators: Fix namespaces kwarg in -random

https://gerrit.wikimedia.org/r/287884

Change 287884 merged by jenkins-bot:
pagegenerators: Fix regression bugs in -random

https://gerrit.wikimedia.org/r/287884

Mpaa closed this task as Resolved.May 10 2016, 9:01 PM