Користувач:BaseBot/addportalarttemplatetoartarticles

Матеріал з Вікіпедії — вільної енциклопедії.
Перейти до навігації Перейти до пошуку
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commonsbasebot;

import java.util.LinkedHashMap;
import net.wikipedia.Wiki;

/**
 *
 * @author Base
 */
public class CommonsBaseBot {

    /**
     * @param args the command line arguments
     */
     public static void main(String[] args) throws Exception {
        Wiki wiki = new Wiki("uk.wikipedia.org");
        wiki.login("Login", "password");
        wiki.setUserAgent("commons bot");
        int limit = 50;
        int section=1;
        wiki.setMarkBot(true);
        wiki.setMarkMinor(true);
        String[] wth = wiki.whatTranscludesHere("Шаблон:Архітектор", Wiki.MAIN_NAMESPACE);
        System.out.println("wth.length="+wth.length);
        for(int i=0; i<wth.length; i++){
            System.out.println("Робота над сторінкою:"+wth[i]);
            String pt=wiki.getPageText(wth[i]);
            if(!pt.contains("{{портал мистецтво}}")|| !pt.contains("Nuvola apps kcoloredit.svg")){
                
                LinkedHashMap<String, String> sMap = wiki.getSectionMap(wth[i]);
                int ss=sMap.size();
                String stxt=wiki.getSectionText(wth[i], ss);
                stxt=stxt.replaceFirst("\n", "\n{{портал мистецтво}}\n");
               
                System.out.println(stxt);
                wiki.edit(wth[i], stxt, "бот додає {{портал мистецтво}}", ss);
                
            }
            else{}
        }
        wiki.logout();
        
        
      
    }
     
         public static String replaceAll(String str, String pattern, String replace) {
        int s = 0;
        int e = 0;
        StringBuffer result = new StringBuffer();
        while ((e = str.indexOf(pattern, s)) >= 0) {
            result.append(str.substring(s, e));
            result.append(replace);
            s = e + pattern.length();
        }
        result.append(str.substring(s));
        return result.toString();
    }
}