Difference between pages "User:Mathieu/Test" and "User:Mathieu/bot"

From Event-B
< User:Mathieu(Difference between pages)
Jump to navigationJump to search
imported>Mathieu
m
 
imported>Mathieu
m (→‎Add a category to the last uploaded images: Replace text matching regular expressions)
 
Line 1: Line 1:
<center>
+
A bot may be a useful tool to help a wiki maintenance.
{|
 
|<math>(-E)*\ldots*(-F)\;==\; E*\ldots*F  </math> (if an even number of -)
 
|-
 
|<math>(-E)*\ldots*(-F)\;==\; -\,(E*\ldots*F)  </math> (if an odd number of -)
 
|}
 
  
<math>
+
I tried to use the python framework provided by http://pywikipediabot.sourceforge.net/. Hereafter are some guidelines to make it work on this wiki.
\frac{\ }{\textbf{H},\textbf{P} \;\;\vdash \;\; \textbf{P}}
 
</math>
 
  
{|
+
== Requirements ==
|<math>\frac{X}{\textbf{H},\textbf{P} \;\;\vdash \;\; \textbf{P}}</math>
+
* Python >2.5
| HYP
 
|}
 
  
{{InfRule|HYP|<math>\frac{}{\textbf{H},\textbf{P} \;\;\vdash \;\; \textbf{P}}</math>}}
+
== Getting pywikipedia framewok ==
</center>
+
Get the source code from subversion:
 +
<pre><nowiki>
 +
(prompt) svn co http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia pywikipedia
 +
</nowiki></pre>
 +
== Configuring the framework for this wiki ==
 +
Add the following <tt>families/eventb_family.py</tt> file (be careful with the indentation):
 +
<pre><nowiki>
 +
# -*- coding: utf-8  -*-
  
==Main page tests==
+
import family
 +
# The event-b family
 +
# user-config.py: usernames['event-b']['event-b'] = 'User name'
 +
class Family(family.Family):
 +
    def __init__(self):
 +
        family.Family.__init__(self)
 +
        self.name = 'eventb'
 +
        self.langs = {
 +
            'eventb': 'wiki.event-b.org',
 +
        }
 +
 
 +
        self.namespaces[4] = {
 +
            '_default': [u'Event-B', self.namespaces[4]['_default']],
 +
        }
 +
 
 +
        self.namespaces[5] = {
 +
          '_default': [u'Event-B talk', self.namespaces[5]['_default']],
 +
        }
 +
 
 +
    def version(self, code):
 +
        return '1.11'
 +
 
 +
    def path(self, code):
 +
        return '/index.php' #The path of index.php, look at your wiki address.
 +
 
 +
    def scriptpath(self,code):
 +
        return ''
 +
   
 +
#    def shared_image_repository(self, code):
 +
#        return ('commons', 'commons')
 +
 
 +
</nowiki></pre>
 +
 
 +
Then add the following <tt>user-config.py</tt> file:
 +
<pre><nowiki>
 +
family='eventb'
 +
mylang='eventb'
 +
usernames['eventb']['eventb'] = 'your_bot_user_name'
 +
</nowiki></pre>
 +
 
 +
== Usage ==
 +
=== Login ===
 +
First you should log in:
 +
<pre><nowiki>
 +
(prompt) python login.py
 +
</nowiki></pre>
 +
=== Upload Images ===
 +
<pre><nowiki>
 +
(prompt) python upload.py -noverify -keep file.png "Image description"
 +
</nowiki></pre>
 +
 
 +
For uploading several images from a directory, I use the following ''sh'' command:
 +
<pre><nowiki>
 +
for i in /tmp/imagedir/* ; do (yes | python upload.py -v -noverify -keep $i "Import of image $i"); done
 +
</nowiki></pre>
 +
 
 +
 
 +
=== Add a category to the last uploaded images ===
 +
For the last 20 images, do :
 +
<pre><nowiki>
 +
python category.py -v add -newimages:20
 +
</nowiki></pre>
 +
 
 +
=== Replace text matching regular expressions ===
 +
<pre><nowiki>
 +
python replace.py -cat -regex '{\\tt ([^}]*)}' '\texttt{\1}'
 +
</nowiki></pre>

Revision as of 11:58, 1 September 2008

A bot may be a useful tool to help a wiki maintenance.

I tried to use the python framework provided by http://pywikipediabot.sourceforge.net/. Hereafter are some guidelines to make it work on this wiki.

Requirements

  • Python >2.5

Getting pywikipedia framewok

Get the source code from subversion:

(prompt) svn co http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia pywikipedia

Configuring the framework for this wiki

Add the following families/eventb_family.py file (be careful with the indentation):

# -*- coding: utf-8  -*-

import family
# The event-b family
# user-config.py: usernames['event-b']['event-b'] = 'User name'
class Family(family.Family):
    def __init__(self):
        family.Family.__init__(self)
        self.name = 'eventb'
        self.langs = {
            'eventb': 'wiki.event-b.org',
        }

        self.namespaces[4] = {
            '_default': [u'Event-B', self.namespaces[4]['_default']],
        }

        self.namespaces[5] = {
           '_default': [u'Event-B talk', self.namespaces[5]['_default']],
        }

    def version(self, code):
        return '1.11'

    def path(self, code):
         return '/index.php' #The path of index.php, look at your wiki address. 

    def scriptpath(self,code):
        return ''
    
#    def shared_image_repository(self, code):
#        return ('commons', 'commons')

Then add the following user-config.py file:

family='eventb'
mylang='eventb'
usernames['eventb']['eventb'] = 'your_bot_user_name'

Usage

Login

First you should log in:

(prompt) python login.py 

Upload Images

(prompt) python upload.py -noverify -keep file.png "Image description"

For uploading several images from a directory, I use the following sh command:

for i in /tmp/imagedir/* ; do (yes | python upload.py -v -noverify -keep $i "Import of image $i"); done


Add a category to the last uploaded images

For the last 20 images, do :

python category.py -v add -newimages:20

Replace text matching regular expressions

python replace.py -cat -regex '{\\tt ([^}]*)}' '\texttt{\1}'