How to speed up Pywikibot?

孤街醉人 提交于 2019-12-04 04:28:54

Use PreloadingGenerator so that pages are loaded in batches. Or MySQLPageGenerator if you use direct DB access.

See examples here.

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.)

I'm using "-pt:1" option in the command to make one edit per second.

I'm currently running the command

python pwb.py category add -pt:1 -file:WX350.txt -to:"Taken with Sony DSC-WX350"

https://www.mediawiki.org/wiki/Manual:Pywikibot/Global_Options

Using PreloadingGenerator from pagegenerators 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:

  • Download a dump of the wiki and read it locally. Wikimedia projects offer dumps updated about once a week.
  • Create an account on Wikimedia Labs and work from there enjoying from faster connection with Wikipedias and updated dumps.

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.

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:

dump_file = hewiktionary-latest-pages-articles.xml.bz2

all_wiktionary = XmlDump(dump_file).parse()
gen = (pywikibot.Page(site, p.title) for p in all_wiktionary if report_problem(p))
gen = pagegenerators.PreloadingGenerator(gen)
for page in gen:
    report_problem(page)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!