Hi all,
on my first steps with Python and Pywikibot, i encounter the following
strange error message:
2024-05-3116:23:19__init__.py, 373in       _flush: VERBOSE
 Dropped throttle(s).
2024-05-3116:23:19http.py, 119in        flush: VERBOSE  Closing
network session.
2024-05-3116:23:19http.py, 123in        flush: VERBOSE  Traceback
(most recent call last):
 File "<frozen runpy>", line 198, in _run_module_as_main
 File "<frozen runpy>", line 88, in _run_code
 File
"C:\Users\florian\AppData\Roaming\Python\Python312\Scripts\pwb.exe\__main__.py",
line 7, in <module>
sys.exit(run())
       ^^^^^
 File
"C:\Users\florian\AppData\Roaming\Python\Python312\site-packages\pywikibot\scripts\wrapper.py",
line 516, in run
  if not execute():
      ^^^^^^^^^
 File
"C:\Users\florian\AppData\Roaming\Python\Python312\site-packages\pywikibot\scripts\wrapper.py",
line 492, in execute
  run_python_file(filename, script_args, module)
 File
"C:\Users\florian\AppData\Roaming\Python\Python312\site-packages\pywikibot\scripts\wrapper.py",
line 149, in run_python_file
  exec(compile(source, filename, 'exec', dont_inherit=True),
 File ".\HandleCommonsOnOSMBot.py", line 192, in <module>
  main()
 File ".\HandleCommonsOnOSMBot.py", line 188, in main
HandleCommonsOnOSMBot(generator=gen_factory.getCombinedGenerator(),
**options).run()
 File
"C:\Users\florian\AppData\Roaming\Python\Python312\site-packages\pywikibot\bot.py",
line 1470, in run
self.generator= (item for item in self.generator)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType'object is not iterable
2024-05-3116:23:19http.py, 132in        flush: CRITICALExiting due
to uncaught exception TypeError: 'NoneType'object is not iterable
2024-05-3116:23:19http.py, 137in        flush: VERBOSE  Network
session closed.
This error encounters when my script is finished and pywikibot closing
the network session. For the complete source code, please see
https://github.com/tohuuuuu/HandleCommonsOnOSMBot/blob/main/HandleCommonsOn…
I took the part starting with "def main(*args: str) -> None:" from
https://doc.wikimedia.org/pywikibot/stable/library_usage.html - maybe
this isn't the correct way to use it? Since the bot code works fine, it
looks like a minor problem, but i'm curious if i did something wrong.
Cheers
Florian
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?
If I've got a Node out of Wikicode.filter(), is there a way to map that back to a location in the original parsed wikitext? Ideally, character offsets for the start and end of the text that makes up the Node.
I'm trying to single-step through pywikibot using vscode. I've got:
certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
iniconfig==2.0.0
mwparserfromhell==0.6.6
packaging==23.2
pluggy==1.4.0
pytest==8.0.2
pytest-mock==3.12.0
pywikibot==8.6.0
requests==2.31.0
urllib3==2.2.1
vscode: Version: 1.87.1
MacOS Ventura 13.6.4
Python 3.11.8
I'm getting a bunch of Pylance errors (warnings?) _basepage.py of the form:
Variable not allowed in type expression
It seems to be complaining about the "Dict" in:
def protection(self) -> Dict[str, Tuple[str, str]]:
Any idea what's going on?
Dear Pywikibot Contributors,
I trust this message finds you well. My name is Abdulrhman Adel, and I'm
enthusiastic about the prospect of contributing to the Pywikibot project.
In my journey as a developer, I've had the opportunity to work on various
projects, including several Python projects developed for hackathons. One
of my most significant achievements is the creation of the A.I.S.L a Sign
Language Assistant. This bot was specifically designed to assist
individuals with sign language.
Pywikibot's role as a Python library and automation tool, developed for
Wikipedia, has captured my interest and I'm eager to contribute my skills
and insights to enhance Pywikibot's capabilities.
Feel free to explore my GitHub profile
<https://github.com/abdulrhman-adel/>and my repositories to gain insight
into my coding style and previous contributions.
Having reviewed the Pywikibot documentation and contributor guidelines, I
am enthusiastic about the prospect of getting involved. Could you please
provide guidance on the next steps or point me to tasks suitable for
newcomers?
Thank you for your time and consideration. I am looking forward to the
opportunity to collaborate with the Pywikibot community.
Best regards,
Abdulrhman Adel