I've built some report tools using Pywikibot. As things are growing it now takes up to 2 hours to finish the reports so I'm looking to speed things up. Main ideas:
- Disable throttling, the script is read-only, so
page.get(throttle=False)
handles this - Cache
- Direct database access
Unfortunately I can't find much documentation about caching and db access. Only way seems to dive into the code, and well, there's limited information about database access in user-config.py
. If there is any, where can I find good documentation about pywikibot caching and direct db access?
And, are there other ways to speed things up?
Use
PreloadingGenerator
so that pages are loaded in batches. OrMySQLPageGenerator
if you use direct DB access.See examples here.
I'm using "-pt:1" option in the command to make one edit per second.
I'm currently running the command
https://www.mediawiki.org/wiki/Manual:Pywikibot/Global_Options
You can download all the data in advance in a dump file in this site http://dumps.wikimedia.org You can then use a two passes - first pass reads the data from the local dump, then the second pass reads only the remote pages for which you found issues in the local dump.
Example:
Looks like
pagegenerators
is indeed a good way to speed up things. The best documentation for that is directly in the source.Even in there it's not directly clear where to put the MySQL connection details. (Will update this hopefully.)
Using
PreloadingGenerator
frompagegenerators
is the simplest way to speed some programs that need to read a lot from online wikis, as other answers have already pointed.Alternative ways are:
Modifying
throttle
might put you in danger of getting blocked if the target wiki has a policy against it - and I'm afraid Wikipedia has such a policy.