Utilisateur:Ir4ubot/Journaux/2009032202
Apparence
import java.net.MalformedURLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Stack;
import net.sourceforge.jwbf.actions.mw.util.ActionException;
import net.sourceforge.jwbf.actions.mw.util.ProcessException;
import net.sourceforge.jwbf.bots.MediaWikiBot;
import net.sourceforge.jwbf.contentRep.mw.Article;
/**
* @author pixeltoo
*
*/
public class Basic
{
private static int CATEGORY_NAMESPACE=14;
private static String strTimeline;
public static void main(String[] args) {
MediaWikiBot b;
try {
b = new MediaWikiBot("http://fr.wikipedia.org/w/");
try {
b.login("Ir4ubot", "****");
Iterable<String> i;
try {
i = b.getCategoryMembers("Admissibilité à vérifier",CATEGORY_NAMESPACE);
int iCounter=0;
i.toString();
Iterator<String> j = i.iterator();
Stack<DataBar> stackDataBar=new Stack<DataBar>();
int iTemp=0;
while(j.hasNext())
{
String strCategory=j.next();
Iterable<String> k=b.getCategoryMembers(strCategory.replace("Catégorie:", ""));
System.out.println("*[["+strCategory+"]]");
Iterator<String> articleIterator = k.iterator();
int articleCounter =0;
while(articleIterator.hasNext())
{
articleIterator.next();
articleCounter++;
}
DataBar dtb=new DataBar();
dtb.setIBegin(iTemp);
iTemp=iTemp+articleCounter;
dtb.setIEnd(iTemp);
dtb.setStrLink(strCategory);
dtb.setStrText(strCategory.replace("Catégorie:Admissibilité à vérifier depuis ", ""));
dtb.setStrName(firstToUpperCase(removeDiacritics(strCategory.replace("Catégorie:Admissibilité à vérifier depuis ", "")).replace(" ", "")));
if (!dtb.getStrName().equals("Categorie:Admissibiliteaverifier,datemanquante"))//remove supplementary category
stackDataBar.push(dtb);
System.out.println(articleCounter+" articles");
iCounter++;
}
System.out.println(iCounter+" catégories");
ListIterator<DataBar> li,lk;
li=stackDataBar.listIterator();
lk=stackDataBar.listIterator();
strTimeline="";
strTimeline+="ImageSize = width:800 height:auto barincrement:25\n";
strTimeline+="PlotArea = left:15 right:30 bottom:30 top:15\n";
strTimeline+="Colors =\n";
strTimeline+=" id:canvas value:rgb(0.97,0.99,1)\n";
strTimeline+=" id:Title value:rgb(0.97,0.97,0.97)\n";
strTimeline+=" id:2006 value:rgb(0.78,0.8,0.8)\n";
strTimeline+=" id:Total value:rgb(0.8,0.8,1)\n";
strTimeline+=" id:grid1 value:rgb(0.80,0.80,0.80)\n";
strTimeline+=" id:grid2 value:rgb(0.90,0.90,0.90)\n";
strTimeline+="Period = from:0 till:2000\n";
strTimeline+="TimeAxis = orientation:horizontal\n";
strTimeline+="ScaleMajor = unit:year increment:1000 start:0 gridcolor:grid1\n";
strTimeline+="ScaleMinor = unit:year increment:50 start:0 gridcolor:grid2\n";
strTimeline+="AlignBars = justify\n";
strTimeline+="BackgroundColors = canvas:canvas bars:canvas\n\n\n\n";
strTimeline+="BarData =\n";
strTimeline+=" bar:Titlebar\n";
while(lk.hasNext())
{
strTimeline+=" "+"bar:"+lk.next().getStrName()+"\n";
}
strTimeline+="PlotData =\n";
strTimeline+=" width:18 fontsize:M textcolor:black align:center\n";
strTimeline+=" bar:Titlebar color:Title shift:(0, -4)\n";
strTimeline+=" from:start till:end text: \"Avancement (le "+getDateTime()+")\"\n";
strTimeline+=" width:18 fontsize:M textcolor:white anchor:from align:left\n\n";
strTimeline+=" color:2006\n";
strTimeline+=" shift:(4, -4)\n\n\n\n";
while(li.hasNext())
{
strTimeline+=li.next()+"\n";
}
Article a;
a=new Article("", "Utilisateur:Ir4ubot/Brouillon", b);
a.setEditSummary("replace text ");
System.out.println(strTimeline);
a.addText("<pre style=\"overflow:auto;\">"+strTimeline+"</pre>\n<timeline>"+strTimeline+"</timeline>"); //replace text by strText
System.out.println(a.getLabel());
try {
b.writeContent(a);
} catch (ProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ProcessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (ActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String removeDiacritics(String s) {
s = s.replaceAll("[èéêë]","e");
s = s.replaceAll("[ûù]","u");
s = s.replaceAll("[ïî]","i");
s = s.replaceAll("[àâ]","a");
s = s.replaceAll("Ô","o");
s = s.replaceAll("[ÈÉÊË]","E");
s = s.replaceAll("[ÛÙ]","U");
s = s.replaceAll("[ÏÎ]","I");
s = s.replaceAll("[ÀÂ]","A");
return s ;
}
public static String firstToUpperCase(String s)
{
return s.substring(0,1).toUpperCase() + s.substring(1);
}
private static String getDateTime() {
DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.FRENCH);
Date date = new Date();
return dateFormat.format(date);
}
}
public class DataBar {
private String strName;
private int iBegin;
private int iEnd;
private String strText;
private String strLink;
/**
* @param iBegin the iBegin to set
*/
public void setIBegin(int iBegin) {
this.iBegin = iBegin;
}
/**
* @return the iBegin
*/
public int getIBegin() {
return iBegin;
}
/**
* @param iEnd the iEnd to set
*/
public void setIEnd(int iEnd) {
this.iEnd = iEnd;
}
/**
* @return the iEnd
*/
public int getIEnd() {
return iEnd;
}
/**
* @param strText the strText to set
*/
public void setStrText(String strText) {
this.strText = strText;
}
/**
* @return the strText
*/
public String getStrText() {
return strText;
}
/**
* @param strLink the strLink to set
*/
public void setStrLink(String strLink) {
this.strLink = strLink;
}
/**
* @return the strLink
*/
public String getStrLink() {
return strLink;
}
public String toString()
{
return " bar:"+this.getStrName()+"\n from:"+this.getIBegin()+" till:"+this.getIEnd()+" text: \"[[:"+this.getStrLink()+"|"+this.getStrText()+" : "+this.getWidth()+" articles]]\" textcolor:black ";
}
public int getWidth()
{
return iEnd-iBegin;
}
/**
* @param strName the strName to set
*/
public void setStrName(String strName) {
this.strName = strName;
}
/**
* @return the strName
*/
public String getStrName() {
return strName;
}
}