Hello all,
After my last mail, you have of course set up a working rewrite development
environment and were wondering how to spread TW integration like a virus
through the scripts/ directory. So, how to do it:
As you will notice, there is now a i18n/ directory inside the scripts/
directory. This directory contains all files exported from TranslateWiki.
The script name defines which TW keys are defined in the file, so
i18n/category.py contains category-*
(category-was-moved<http://translatewiki.net/wiki/Pywikipedia:Category-was-moved/en>,
category-also-in, etc). These are the translations that before were in
scripts/category.py.
Adapting scripts to translatewiki consists of four parts:
* Defining TW keys for translations
* Reading in translations and outputting them into the TW format
* Removing translations from script file
* Adding 'from pywikibot import i18n' and adapting all/most
pywikibot.translate entries with i18n.twtranslate().
*(1) Defining TW keys*
To use isbn.py as an example. There is only one message (only showing german
and english):
msg = {
'de': 'Bot: Formatiere ISBN',
'en': 'Robot: Formatting ISBN',
}
For TW, we define this message as isbn-formatting.
Sometimes pywikibot.translate is used for site- or language-specific
configuration. Don't move those to translatewiki files (yet).
*(2) Reading in translations and outputting them into the TW format*
Although it is possible to do the isbn example by hand, I'll use a script
that can easily be adapted for a larger number of messages. Don't
forget to source
bin/activate your virtualenv!
The script is available at http://pastebin.com/u2XrKt5b (too long to paste
in this e-mail)
For other scripts, you have to adapt at least lines 2, 6 and 12. Line 12 has
a list of tuples (old dict, translatewiki key).
If the messages have (one or more) parameters, you should change them to *named
parameters*, so translators can move them around in the message. See lines
15 and 16 for an example of how to do this.
Running this script gives you a new file, i18n/isbn.py
*Test* the translation:
(pwbde)/rewrite/scripts$ python
>>> from pywikibot import i18n
>>> i18n.twtranslate("de", "isbn-formatting")
u'Bot: Formatiere ISBN'
hurrah!
*(3) Removing translations from the script file*
Use a sledgehammer, jackhammer or scalpel. Whatever works for you. In the
case of isbn.py, lines 49 to 61.
*(4a) Add from pywikibot import i18n*
-from pywikibot import pagegenerators
+from pywikibot import pagegenerators, i18n
*(4b) Adapting all/most pywikibot.translate entries*
Search for pywikibot.translate. Change the following:
pywikibot.translate(site, msg) % (param_1, param_2)
to
i18n.twtranslate(site, "tw-key-for-msg", {'param_1': param_1, 'param_2':
param_2})
With *'tw-key-for-msg'* referring to the tw key you thought up for *msg*,
and *'param_1'* and *'param_2'* (the dictionary keys) referring to the *named
parameters* you introduced in step 2.
For isbn.py, this is simpler:
- self.comment = pywikibot.translate(pywikibot.getSite(), msg)
+ self.comment = i18n.twtranslate(pywikibot.getSite(),
'isbn-formatting')
*Congratulations! *You have adapted a script to use translatewiki
translations!
Of course, before committing, *test* the script:
(pwb)/rewrite/scripts$ *python isbn.py -page:Gebruiker:Valhallasw -to13
-format*
(...)
Page [[Gebruiker:Valhallasw]] saved
yielding:
(huidig | vorige<http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw&diff=2401141…>
) 16 jan 2011 14:29<http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw&oldid=240114…>
Valhallasw <http://nl.wikipedia.org/wiki/Gebruiker:Valhallasw>
(Overleg<http://nl.wikipedia.org/wiki/Overleg_gebruiker:Valhallasw>
| bijdragen <http://nl.wikipedia.org/wiki/Speciaal:Bijdragen/Valhallasw>) k
(1.735 bytes) (Bot: ISBN opgemaakt) (ongedaan
maken<http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw&action=edit&…>
)
And, as a last step, *commit* the script (and the translations!) to the svn
repository: http://www.mediawiki.org/wiki/Special:Code/pywikipedia/8838
Good luck adapting scripts!
Best regards,
Merlijn 'valhallasw' van Deen
Hello everyone,
During the Amsterdam Hackathon, we - siebrand, roberthl and myself -
have been working on integrating TranslateWiki with pywikipedia.
Yesterday I have committed most of the changes to the rewrite branch.
On TranslateWiki, the translations have been online since friday. We
already have had 160 contributions!
At the moment, only replace.py uses TW translations. I will commit
updated versions for category.py and interwiki.py today. Adapting a
script to use TW takes about fifteen minutes. I will send an e-mail to
pywikipedia-l on how to do this later today.
Please note the changes will *not* be backported to trunk, as the
changes are significant. To help people in switching to the rewrite
(it's practically painless!), I will send (another) e-mail to
pywikipedia-l on how to set it up.
Best regards,
Merlijn 'valhallasw' van Deen
Hello all,
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*.
As a prerequisite, install virtualenv. All other dependencies should be
installed automatically. The following is a log of what I did - and what you
could/should do ;-) The output is monospaced, the things I entered are *bold
*.
------------------------------------------------
valhallasw@dorthonion:~/src$ *virtualenv pwb*
New python executable in pwb/bin/python
Installing setuptools............done.
valhallasw@dorthonion:~/src$ *cd pwb*
valhallasw@dorthonion:~/src/pwb$ *source bin/activate # activate virtualenv*
(*pwb*)valhallasw@dorthonion:~/src/pwb$ *mkdir src*
(*pwb*)valhallasw@dorthonion:~/src/pwb$ *cd src*
(*pwb*)valhallasw@dorthonion:~/src/pwb/src$ *svn co svn+ssh://
svn.wikimedia.org/svnroot/pywikipedia/branches/rewrite/ . # note trailing
dot*
A generate_user_files.py
A pywikibot
(...snip...)
Checked out revision 8837.
(*pwb*)valhallasw@dorthonion:~/src/pwb/src$ *python setup.py develop*
Downloading
http://pypi.python.org/packages/source/d/distribute/distribute-0.6.10.tar.gz
(...snip...)
Finished processing dependencies for Pywikipediabot==2.0alpha
Your default user directory is "/home/valhallasw/.pywikibot"
How to proceed? ([K]eep [c]hange) *c*
New user directory? */home/valhallasw/src/pwb/conf*
OK: Created new directory.
WARNING: Your user files will be created in the directory
'/home/valhallasw/src/pwb/conf' you have chosen. To access these files, you
will either have to use the argument "-dir:/home/valhallasw/src/pwb/conf"
every time you run the bot, or set the environment variable "PYWIKIBOT2_DIR"
equal to this directory name in your operating system. See your operating
system documentation for how to set environment variables.
Is this OK? ([yes], [N]o) *y*
Do you want to copy user files from an existing pywikipedia installation? *y
*
Path to existing wikipedia.py? */home/valhallasw/src/pywikipedia/trunk*
NOTE: user-config.py already exists in the directory
Create user-fixes.py file? ([y]es, [N]o) *n*
(*pwb*)valhallasw@dorthonion:~/src/pwb/src$ *echo "export
PYWIKIBOT2_DIR=/home/valh allasw/src/pwb/conf" >> ../bin/activate*
(*pwb*)valhallasw@dorthonion:~/src/pwb/src$ *source ../bin/activate*
(*pwb*)valhallasw@dorthonion:~/src/pwb/src$ *cd scripts/*
(*pwb*)valhallasw@dorthonion:~/src/pwb/src/scripts$ *python touch.py
Gebruiker:Valhallasw*
Password for user valhallasw on wikipedia:nl:
Logging in to wikipedia:nl as valhallasw
Retrieving 1 pages from wikipedia:nl.
Page [[Gebruiker:Valhallasw]] saved
-----------------------------------------------------------------------------------
Now, the next time you want to run the bot, you have to do the following:
-----------------------------------------------------------------------------------
valhallasw@dorthonion:~$ *cd ~/src/pwb/src/scripts/*
valhallasw@dorthonion:~/src/pwb/src/scripts$ *source ../../bin/activate*
(*pwb*)valhallasw@dorthonion:~/src/pwb/src/scripts$ *python touch.py
Gebruiker:Valhallasw*
Password for user valhallasw on wikipedia:nl:
Logging in to wikipedia:nl as valhallasw
Retrieving 1 pages from wikipedia:nl.
Page [[Gebruiker:Valhallasw]] saved
-----------------------------------------------------------------------------------
Best regards,
Merlijn van Deen
The help of replace.py says that it will work on all pages found with a
search. As far as I see, this is not the truth -- in two cases listed it
exactly 100 titles to work on, while there were more than 100. (I also used
-namespace:0 in command line.)
--
Bináris
Hello,
I am moving my scripts from pywikipedia to pywikibot and I am facing a
connection issue. WIth pywikipedia, my login was good for a long time.
With pywikibot I have to login every 2 weeks or so. Is there a way that
the login can be valid for a longer period of time with pywikibot?
Thanks,
N.
Hi,
do you think this could easily be solved? Either to add a new section to a
page instead of downloading and rewriting the whole one, or to open and save
an existing section as we do it without bots.
This would decrease the load of the bot as well as the risk of edit
conflicts for the bot or for human users.
Bináris
2010/11/7 SourceForge.net <noreply(a)sourceforge.net>
> Feature Requests item #3104703, was opened at 2010-11-07 17:57
> Message generated for change (Tracker Item Submitted) made by binbot
> You can respond by visiting:
>
> https://sourceforge.net/tracker/?func=detail&atid=603141&aid=3104703&group_…
>
> Please note that this message will contain a full copy of the comment
> thread,
> including the initial issue submission, for this request,
> not just the latest update.
> Category: None
> Group: None
> Status: Open
> Priority: 5
> Private: No
> Submitted By: Bináris (binbot)
> Assigned to: Nobody/Anonymous (nobody)
> Summary: Add new section to a page
>
> Initial Comment:
> Hi! Wikipedia.Page has now to saving methods, put(newtext) and
> put_async(newtext). I ask you to introduce a third one:
> newsection(title,newtext). It should work as ...action=edit§ion=new, so
> we shouldn't bother the old content of the page to add something to the end.
>
> Thanks a lot!
>
> ----------------------------------------------------------------------
>
> You can respond by visiting:
>
> https://sourceforge.net/tracker/?func=detail&atid=603141&aid=3104703&group_…
>
Hi,
I'm trying to set up automatic discussion archiving on English Wikisource.
I attempted to follow all instructions related to pywikipediabot. All the
relevant information can be found at
http://en.wikisource.org/wiki/User:Spangineer/Sandbox3 . If more is needed,
please let me know: thanks.
--Spangineer
On 2 January 2011 15:46, <info(a)gno.de> wrote:
> I downloaded r2.7.1 (timestamp 27.11.2010) from www.python.org but this bug is still there. Where do I find the correction patch?
The bug has been fixed in the repository, not in any releases (yet).
See http://bugs.python.org/issue10254#msg124800 .
Best regards,
Merlijn
Hi xqt,
First of all, thanks for all the effort you're putting into
pywikipediabot. However,
On 26 December 2010 17:43, <xqt(a)svn.wikimedia.org> wrote:
> Log Message:
> -----------
> Some Russian and Ukrainian translations; minor changes from rewrite
Could you split such commits, please, into one 'translation' commit
(or even better: two, one for russian and one for ukrainian), and one
rewrite-to-trunk port?
Additionally, this:
> - ['Yes', 'No', 'Add an alternative', 'Give up'],
> - ['y', 'n', 'a', 'g'])
> + ['Yes', 'No', 'Add an alternative', 'Give up'],
> + ['y', 'n', 'a', 'g'])
seems to be a purely whitespace change. Could you check diffs to
prevent committing them?
Thanks!
Merlijn