/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package wikicatinfo;
import java.util.HashMap;
import net.wikipedia.Wiki;
/**
*
* @author Base
*/
public class CategoryStat {
public static void main(String[] args) throws Exception {
}
public void CatStat(String Login, String password, String cat, String proj, int deep) throws Exception {
Wiki w = new Wiki(proj+".org");
w.login(Login, password.toCharArray());
totalSize=0;
totalP=0;
String сat=cat;
CatStatD(w, cat, deep);
resStr="Категорія:"+сat+" включає "+ totalP+ " сторінок із загальним обсягом " + totalSize +"б (" +(totalSize/1024)+"кб)";
w.logout();
}
public void CatStatD(Wiki w, String cat, int deep) throws Exception {
String сat=cat;
String[] categoryMembers = w.getCategoryMembers(сat, 0);
localSize=0;
localP=0;
totalP += categoryMembers.length;
localP += categoryMembers.length;
for (int i = 0; i < categoryMembers.length; i++) {
HashMap<String, Object> pageInfo = w.getPageInfo(categoryMembers[i]);
curSize =(Integer) pageInfo.get("size");
totalSize+=curSize;
localSize+=curSize;
System.out.println(categoryMembers[i]+"\'s size is "+ curSize+"б ("+(curSize/1024)+"кб)");
}
String resStrT="Категорія:"+сat+" включає "+ localP+ " сторінок із загальним обсягом " + localSize +"б (" +(localSize/1024)+"кб)";
System.out.println(resStrT);
if(deep>1){
deep-=1;
String[] categoryCatMembers = w.getCategoryMembers(сat, 14);
for (int j = 0; j < categoryCatMembers.length; j++) {
categoryCatMembers[j]=categoryCatMembers[j].replaceFirst(categoryCatMembers[j].substring(0, categoryCatMembers[j].indexOf(":")+1), "");
CatStatD(w, categoryCatMembers[j], deep);
}
}else{
}
}
//Var declaration
public static int curSize;
public static int totalSize, localSize;
public static String Cat;
public String resStr;
public static int totalP, localP;
}
//14 categoty