anon = '89.134.24.79/16'
user = pywikibot.User(site, anon)
for contrib in user.contributions():
print(contrib[1])
This makes nothing.
(There is a massive vandal from a range, and I want to hide all the
inappropriate contents made by him.)
--
Bináris
*TL;DR*: we can mass hide vandal revisions from pages histories, e.g.
obscene images and edit comments.
Of course, this needs admin rights.
It is easy to mass hide revisions from the history of one page without bot,
just click checkboxes. But it is tiring, if several pages are involved.
I wrote a script that is not ready to publish, and I won't show it for the
vandal, and needs manual editing. But I can send it in a private mail to
those who are interested.
The API documentation is here:
https://www.mediawiki.org/wiki/API:Revisiondelete
But it is not complete. I learned on my own that multiple revids may
concern the same page. We don't have to write the title into the request,
but must group the revisions by page.
The required format is e.g. 27009438|27009402|27009353|27009335|27009151
with pipe, all ids belong to the same page, otherwise they won't all be
processed, just the first page. This is an undocumentetd feature. :-)
Sample code fragment (run with -user:myadminaccount):
hide = 'content|comment|user' # Just to show the syntax, keep what you need
reason = 'Vandalism'
def gen() -> Iterator[str]:
"""Yield ids to hide in the above form, page by page. Here comes your
work."""
yield' 27009438|27009402|27009353|27009335|27009151' # Example
token = site.get_tokens(['csrf']).get('csrf') # get a single token
for ids in gen():
params = {'action': 'revisiondelete',
'type': 'revision',
'ids': ids,
'hide': hide,
'token': token,
'reason': reason,
}
request = site.simple_request(**params)
request.submit()
To get the ids use for contrib in user.contributions():
contrib[0] will be the page object, while contrib[1] the revision id for
each contribution.
--
Bináris
If I do:
wikicode = mwparserfromhell.parse("This is\n__TOC__\nan article.")
I get back a single Text node. For what I'm doing, it would be really
convenient to have the __TOC__ be parsed as it's own node, i.e. instead
of a single Text node with 'This is\n__TOC__\nan article.', I'd like to
get 3 Text nodes, with 'This is\n', '__TOC__', '\nan article.']
The best I've come up with so far is to pre-process the text to insert
HTML comments around the __TOC__, but that's really ugly for so many
reasons. The next best I've come up with is to post-process the nodes
to manually split any Text node that has __TOC__ in it into 2 or 3 Text
nodes, but that's really ugly for so many other reasons. Anybody have
any better ideas?
Hi pywikibot experts
I am using the following command string (Python 3.12, Windows 11):
python pwb.py upload <full source file path on local drive> -ignorewarn
-noverify -prefix:WA00 -descfile:full description file path on local drive>
upload.py asks me to confirm the target file name. I would prefer a
completely silent upload without the need for confirmation.
Is there a "-silent" flag that I can use?
Also, I noticed I can only execute commands like "python pwb.py ....." if I
am in the folder
C:\Users\<myusername>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages
This folder is in my "path" (see below).
How can I make pwb.py accessible from other folders?
Thanks
James Trevelyan
Path=
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Program Files (x86)\Common
Files\Intel\SharedLibraries\redist\intel64\compiler;
C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\System32\OpenSSH\;
C:\Program Files\dotnet\;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;
C:\Users\<myusername>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Users\<myusername>\AppData\Local\Microsoft\WindowsApps;
M: +61 402 481 167 (WhatsApp) E: James.Trevelyan(a)uwa.edu.au
33 Brockman Ave, Dalkeith WA 6009
0402 48 1167
Hi,
given a category c and a page p, p is listed in c.articles(recurse=True)
But is shouldn't... And I don't know the depth of it.
Is there a simple way to find a path between them, and guess, why is the
page in the category?
(I spent 10 minutes with manual trying, total fail.)
--
Bináris
The docs for BasePage.get() say:
pywikibot.exceptions.IsRedirectPageError – The page is a redirect. The argument of the exception is the title of the page it redirects to.
but that doesn't seem to be what's actually happening:
> from pywikibot import Site, Page
> from pywikibot.exceptions import IsRedirectPageError
>
> site = Site("en")
>
> page = Page(site, "Template:shortdescription")
> try:
> print(page.get())
> except IsRedirectPageError as ex:
> print(f"{ex.args=}")
prints
> ex.args=(Page('Template:Shortdescription'),)
Am I just not understanding the doc correctly?