|Please share your thoughts about whether to keep this page at Wikibooks.
Maintain this notice so this page can receive a fair review and people have time to boldly address reasonable concerns through concrete improvements. Remove or replace this notice after discussion concludes and a community decision is made. Please also consider notifying the primary contributors on their discussion page with
How to report a bug
When you report a bug please try to include:
- PyWikipediaBot version in use. It's recommended to test if the bug is still present in latest SVN revision available.
- Python version (python -V) and operating system you use (e.g. Windows, Linux, MacOS...)
- For above purpose, version.py will be useful.
- A nice summary
- Full description of the problem/report
- How to reproduce bug full information (script, command line, family, and language used)
- The console output provided by the script (included the Python traceback if you are reporting a crash)
To submit a new bug visit the bug tracker provided by SourceForge.
If you have a function you want to have a bot for that is not yet provided by one of the bots, you can ask one of the programmers to write it for you. Or even better, you can try to work on the bots yourself. Python is a nice language, and not hard to learn. We will welcome you.
Here and in wikipedia.py, there are some very basic tips for getting started writing your own bot:
- be sure you've set up your user-config.py file (see above)
- To gain access to the pywikipedia framework, use:
- to retrieve a page, use the following, where pageName is, e.g., "Wikipedia:Bots" or "India":
site = wikipedia.getSite() page = wikipedia.Page(site, u"pageName") text = page.get(get_redirect = True)
- to update a page, use:
page.put(u"newText", u"Edit comment")
- look at some of the pywikipedia files for other ideas -- basic.py is relatively easy to read even if you're new to pywikipedia.
- you can find all available Page methods in the wikipedia.py file.
- basic.py gives you a setup that can be used for many different bots, all you have to do is define the string editing on the page text.
- To iterate over a set of pages, see pagegenerators.py for some objects that return a set of pages. An example use of the CategoryPageGenerator that does something for each page in the Category:Living people category:
import catlib import pagegenerators import wikipedia site = wikipedia.getSite() cat = catlib.Category(site,'Category:Living people') gen = pagegenerators.CategorizedPageGenerator(cat) for page in gen: #Do something with the page object, for example: text = page.get()
If you changed the bot and want to send a patch to the maintainer,
- Update to the current version (it will merge your changes with the improvements already committed to the SVN Repository),
- Resolve any conflicts caused by the update (grep for "=====" ;-) and
$ svn diff > svn.diff
Review the diff to ensure it only includes the changes you want to contribute. The lines at the beginning starting with "?" should be removed.
If you are in direct contact with a Pywikipediabot developer, you can send the file svn.diff to him, but preferably attach the patch to a ticket in the Pywikipedia bug tracking system.
It is a common need to run python wikipedia bot under different accounts (main and/or multiple bot accounts). It can be done in two ways.
Separate pywikipedia distributions
One can install completely separate instances of pywikipedia in different directories (1 for each account) and have diferent
user-config.py files in each of them. However, when updating the installation via SVN, one needs to run
svn update on each folder separately. Also, every installation takes some disk space, which might be a problem on accounts with limited quota.
Let's assume user
foo has a current SVN working copy of pywikipedia in
/home/foo/pywikipedia. For each of the accounts, he creates a separate directory:
foo@bar:~$ mkdir foobot foo@bar:~$ cd foobot
Pywikipedia needs then some symlinks to the main code tree created in the working directory:
foo@bar:~/foobot$ ln -s ~/pywikipedia/families foo@bar:~/foobot$ ln -s ~/pywikipedia/userinterfaces
user-config.py for this account must be created as described in Configuration section above.
Finally, the bot must be logged in the usual way:
foo@bar:~/foobot$ python ~/pywikipedia/login.py
The working directory is ready. The scripts will however require a slight modification to run (the path to the pywikipedia tree must be added to Python's path).
import sys, os sys.path.append(os.environ['HOME'] + '/pywikipedia') import wikipedia
That's all. Updating to the newest version of pywikipedia on all accounts at once is now a matter of running
svn update only in the
On Windows 2000+ with NTFS
A similar set-up can be created on Windows systems running Windows 2000 or later that use NTFS as their filesystem. This can be achieved by using the
junction tool (available from Microsoft's website, part of the sysinternals suite).
As above, create your new directory, but to create the symlinks, create
userinterfaces as directories inside of that. (NB: The cmd.exe
mkdir appears not to work properly in all the time, so using the Right-click->New menu or File->New menu is suggested.)
C:\...> junction families C:\pywikipedia\families C:\...> junction userinterfaces C:\pywikipedia\userinterfaces
The rest of the method is the same as above.
Symlink/junctions should be deleted using the
junction program, as you may accidentally lose data in the original directory (see ).
Bot & Proxy
There is probably (not tested!) draft workaround described here.