My old problem is that repalce.py can't write the pages to work on into a
file on my disk. I have used a modificated version for years that does no
changes but writes the title of the involved pages to a subpage on Wikipedia
in automated mode, and then I can make the replacements from that page much
more quickly than directly from dump or living Wikipedia. This is slow and
generates a plenty of dummy edits.
In other words, replace.py has a tool to get the titles from a file (-file)
or from a wikipage (-links), but has no tool to generate this file.
Now I am ready to rewrite it. This way we can start it and the bot will find
all the possible articles to work on and save the titles without editing
Wikipedia (and without artificial delay), meanwhile we can have the lunch or
run a marathon or sleep. Then we make the replacements from this with -file.
My idea is that replace.py should have two new parameters:
-save writes the results into a new file instead of editing articles. It
overwrites existing file without notice.
-saveappend writes into a file or appends to the existing one.
-save writes and appends (primary mode)
-savenew writes and overwrites
The help is here:
So we have to import codecs.
My script is:
tutuzuzu=u'# %s\n' %page.aslink() <-- needs rewrite to the new syntax
articles.write(unicode(tutuzuzu)) <-- needs further testing, if nicode() is
It works fine except '\n' is a unix-styled newline that has to be converted
by lfcr.py in order to make it readable with notepad.exe.
This is with constant filename, that should be developed to get from command
Your opinions before I begin?
I want to read a special page with Page.get(). The message is:
File "C:\Program Files\Pywikipedia\wikipedia.py", line 601, in get
raise NoPage('%s is in the Special namespace!' % self.aslink())
What is the solution?
On Mon, Apr 25, 2011 at 7:49 AM, Merlijn van Deen <valhallasw(a)arctus.nl> wrote:
> Whoo! Great work :-) Tests always are good contributions :-)
> On a sidenote - is there a reason you're implementing these in 'trunk' and
> not in 'rewrite'? Of course, these contributions are very welcome in the
> trunk, but I still think it would be good to push the rewrite branch.
I'm working off trunk because it is trunk.
I'd assumed that the rewrite branch was a single-purpose branch to
rewrite something, and that it would be merged back when it is stable.
Is it stable?
Is there any documentation on what the plans are for the rewrite branch?
Is there a roadmap to finish it?
Is see now that the rewrite branch has more unit tests, but more are needed.
Is there a need to create a backwards compatibility layer?
Or, is everyone except me using the rewrite branch? ;-)
*As several people have mentioned they had trouble starting with the rewrite
branch, I decided to do a step-by-step log of installing the rewrite in a
way that is good for developing -- this means you are able to edit the
framework files, while not inflicting any changes on other users (or other
bots you run!) of the system. By using setup.py develop, edits you make to
the framework will immediately be used (no need to setup.py install them),
but only within the virtualenv.*
*This is the windows version of my earlier email*
I do not run python on windows, so this is a tutorial that starts with
installing python. It's a bit rougher than the unix one, as I did not want
to spend too much time on it.
1. Install python 2.7
*not* use the 64-bit version, due to http://bugs.python.org/issue6792 )
2. Install Setuptools
3. Install Virtualenv
4. create a virtualenv for pwb
New python executable in pywikibot\Scripts\python.exe
5. Go to C:\Users\valhallasw\pywikibot and use tortoisesvn to get the
6. create a shortcut to cmd /k
with working path C:\Users\valhallasw\pywikibot\rewrite
7. Use the shortcut. You now have a new cmd.exe window
8. python setup.py develop
Your default user directory is
How to proceed? ([K]eep [c]hange)
change, to c:\users\valhallasw\pywikibot\conf\
Answer 'y' to the warning prompt (not 'yes')
Do you want to copy files: y
[note: I copied my unix user-config.py to c:\users\valhallasw\pywikibot]
Path to existing wikipedia.py? C:\Users\valhallasw\pywikibot
NOTE: user-config.py already exists in the directory
Create user-fixes.py file? ([y]es, [N]o) n
(pywikibot) C:\Users\valhallasw\pywikibot\rewrite>echo SET
(DON'T put a space between f and >>!)
Close the window, and
9. Use the shortcut from (7) again
You should now have a cmd.exe with a working pywikibot setup!
(pywikibot) C:\Users\valhallasw\pywikibot\rewrite\scripts>python touch.py
Retrieving 1 pages from wikipedia:nl.
Page [[Gebruiker:Valhallasw]] saved
NOTE: you *must* use 'python' in front of the script name, or python will
not find the pywikibot directory.
I wrote a piece of code that can transform numbers *to* and* from* Roman
numbers from 1 to 999 (because they are regular in this range).
Is anybody interested to put it in some core modul? Then I can make it a bit
nicer. I saw them in date.py until XXX as a pure list.
I collected month names at
as shown in archivebot.py. I need it for writing and testing the
which has to recognize short and long month names in archive name patterns.
The relevant part of my code is:
* text += '<br>'.join([Site.mediawiki_message(MonthsS[i]) for i in
range(12)]) + '\n|'
text += '<br>'.join([Site.mediawiki_message(MonthsL[i]) for i in
*for each Site in site.validLanguageLinks().
If there is any Dutch here, please check the *nl* row, because I saw that
archivebot.py handles it in a specific way that I don't understand, and
cannot check because of different locale.
Now, some rows show irregular behavior which I don't understand.
1. In rows *ne* and *ti* a part of the short names seems to be native,
and some of the short names English. (Apr, Oct in *ne* and from Jul to
Dec in *ti*.) Is that perhaps a MediaWiki bug?
2. In the last row, *zu*, all the long names have a 'u' at the beginning,
just as in Python Unicode strings. Is that correct or some misbehaviour?
3. In the row *ba* there are two short names (ғин, май) that don't fit in
the line. Or is that the other ten? They are different and lower case, while
the others upper case and identical to the long name. Is that a bug or a
feature? If bug, is it in MediaWiki?
4. There are two rows, *ba* and *ky*, where there are alternative
versions in parenthesis, the basic version being *almost* identical to
Russian. Does it mean that any of the given versions may appear in that wiki
as a month name?