Manual talk:Pywikibot/listpages.py

About this board

Option -format : where is the call to footnote '(*)' ?

4
Summary by Wladek92

done; thanks.

Wladek92 (talkcontribs)

No call to reference '(*)' found in the description of first option format

(*) requires that "<tvar|outputlang>-outputlang:</>lang" is set.

obsolète ?

Shirayuki (talkcontribs)
Wladek92 (talkcontribs)

ok, so markup is wrong. The star is only related to option 7. And num is for all values of the option.

        7 - u'{num:4d} {page.loc_title:<40} {page.trs_title:<40}'
            --> 10 localised_Namespace:PageTitle outputlang_Namespace:PageTitle
            (*) requires "outputlang:lang" set.

        num is the sequential number of the listed page.

Christian 🇫🇷 FR (talk) 08:52, 23 May 2021 (UTC)

Shirayuki (talkcontribs)

Can we get content from deleted pages?

4
MrDupin (talkcontribs)

I would like to get content of deleted pages using a bot. Can this script do this? If not, is there any way I can do this?

Thank you.

Dvorapa (talkcontribs)

Users with admin rights on your wiki can do this. If you are not, ask them. If you are, then Special:Undelete page is there for this purpose

MrDupin (talkcontribs)

I am an admin on the particular wiki, but I want to get the content of multiple deleted pages at the same time, automatically.

I think that for normal pages, the 'get' parameter gets the content/text of a page/pages. Is there a way to get the content/text for deleted pages automatically?

Dvorapa (talkcontribs)
Reply to "Can we get content from deleted pages?"

Parameters not obeyed?

6
Gamren (talkcontribs)

I wanted a list of all entries in wt:Category:Danish verbs that end in "s". I navigated to ...\pywikibot\core_stable and typed

py pwb.py listpages -titleregex:'.{2,}s' -cat:Danish verbs

the entries I do get are neither in the category nor end with "s". I got two warnings:

...\data\api.py:282: UserWarning: Unexpected overlap between action and query submodules: frozenset({'readinglists'})

...\family.py:930: FamilyMaintenanceWarning: Family name wikimediachapter does not match family module name wikimedia

I am quite able to use replace.py ([https://en.wiktionary.org/w/index.php?title=User:Gamren&diff=48437681&oldid=48400609]). Please tell me if more information is needed.

User:Octahedron80?__~~~~
Octahedron80 (talkcontribs)

How about this:

listpages -titleregex:"s$" -cat:"Danish verbs"

Do not forget quotes. For other messages, I don't know.

PS. You may need to add -ns:0 to filter only main namespace.

Gamren (talkcontribs)

Thank you for answering. That did succeed in filtering out entries that don't end in "s", but it still doesn't care about the category. I tried both with and without quotes around "Danish verbs".__~~~~

Octahedron80 (talkcontribs)

Did you set family to wiktionary and lang to en yet? (or mylang in user-config.py) I tried my answer on PAWS and it had no problem.

Gamren (talkcontribs)

Yes I did, and the articles I was given were from en.wikt.__~~~~

Octahedron80 (talkcontribs)

You may want to try on this: https://paws.wmflabs.org

After log in then make a new terminal. You can start command with pwb.py.

In my opinion, your pywikibot may be out of date, or misconfigured.

Reply to "Parameters not obeyed?"
David.Mirth (talkcontribs)

Sorry for a stupid question, but how do I export the list into a .txt file?

Octahedron80 (talkcontribs)

Append your command with

> somefile.txt

This is common syntax to export output buffer to a file.

Vladis13 (talkcontribs)

This works in Linux, but not in Windows.

Octahedron80 (talkcontribs)

Windows works too. Try it.

Vladis13 (talkcontribs)
Octahedron80 (talkcontribs)
Vladis13 (talkcontribs)
> python pwb.py listpages -start:s -limit:5 > file.txt
<Unicode redirected stdout>.write: TypeError('write() argument must be str, not bytes',)
Traceback (most recent call last):
  File "pwb.py", line 270, in <module>
    if not main():
  File "pwb.py", line 264, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 109, in run_python_file
    main_mod.__dict__)
  File ".\scripts\listpages.py", line 240, in <module>
    main()
  File ".\scripts\listpages.py", line 223, in main
    pywikibot.stdout(page_fmt.output(num=i, fmt=fmt))
  File "c:\pwb\pywikibot\bot.py", line 473, in stdout
    logoutput(text, decoder, newline, STDOUT, **kwargs)
  File "c:\pwb\pywikibot\bot.py", line 438, in logoutput
    logger.log(_level, text, extra=context, **kwargs)
  File "c:\python35\lib\logging\__init__.py", line 1345, in log
    self._log(level, msg, args, **kwargs)
  File "c:\python35\lib\logging\__init__.py", line 1415, in _log
    self.handle(record)
  File "c:\python35\lib\logging\__init__.py", line 1425, in handle
    self.callHandlers(record)
  File "c:\python35\lib\logging\__init__.py", line 1487, in callHandlers
    hdlr.handle(record)
  File "c:\python35\lib\logging\__init__.py", line 855, in handle
    self.emit(record)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 503, in emit
    return self.UI.output(text, targetStream=self.stream)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 194, in output
    self._print(text, targetStream)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 137, in _print
    self.printNonColorized(text, targetStream)
  File "c:\pwb\pywikibot\userinterfaces\terminal_interface_base.py", line 129, in printNonColorized
    targetStream.write(line)
  File "c:\pwb\pywikibot\userinterfaces\win32_unicode.py", line 254, in write
    self._stream.write(text)
TypeError: write() argument must be str, not bytes
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort
Octahedron80 (talkcontribs)

^ It was going to work. I think you have issue with Unicode instead. 😅

David.Mirth (talkcontribs)

I have the same problem as mentioned above, I thought I am doing sth wrong... The problem is probably in Unicode or something, a friend of mine discusses this in a python forum, we'll se :)

Vladis13 (talkcontribs)

I tried change codepage of console via 'chcp 65001' and 'chcp 1252'. The console, the script, and script out is good understand utf-8. (Like python pwb.py listpages -subcatsr:"Категория:Родившиеся в IX веке".) Python good open|write file|console on utf-8. The error is only when python redirect stdout to file in Windows.

Reply to "Output"
There are no older topics