Wikipedysta:Olafbot/OlafbotDaysOfYear.java


/*                                         */
/*          Olafbot for Wikipedia          */
/*                                         */
/*             Olaf Matyja 2003            */
/*                                         */

import java.lang.*;
import java.net.*;
import java.io.*;
import java.io.Reader.*;

public class OlafbotDaysOfYear {
    //polish letters
    final static String a="%C4%85";
    final static String c="%C4%87";
    final static String e="%C4%99";
    final static String l="%C5%82";
    final static String n="%C5%84";
    final static String o="%C3%B3";
    final static String s="%C5%9B";
    final static String x="%C5%BA";
    final static String z="%C5%BC";
    final static String A="%C4%84";
    final static String C="%C4%86";
    final static String E="%C4%98";
    final static String L="%C5%81";
    final static String N="%C5%83";
    final static String O="%C3%93";
    final static String S="%C5%9A";
    final static String X="%C5%B9";
    final static String Z="%C5%BB";

    //connect with the server
    static void connect(String request,String content) throws Exception {
        Socket socket=null;
        try {
            socket= new Socket(InetAddress.getByName("pl.wikipedia.org"),80);
            DataInputStream input = new DataInputStream(socket.getInputStream()); 
            PrintWriter output = new PrintWriter(socket.getOutputStream(),true);

            output.println(
                request+
                "Content-type: application/x-www-form-urlencoded\n"+
                "Accept: */*\n"+
                "User-Agent: OlafBot\n"+
                "Host: pl.wikipedia.org\n"+
                "Connection: Keep-Alive\n"+
                "Cache-Control: no-cache\n"+
                "Cookie: plwikiUserName=Olafbot; "+
                        "plwikiSession=(...); "+ //authorization data omited
                        "plwikiUserID=2189; "+
                        "plwikiPassword=(...)\n"+//authorization data omited
                "\n"+
                content
            );

            String text="", inputLine;
            while ((inputLine = input.readLine()) != null) {
                text+=inputLine;
                //System.out.println(inputLine);
            }
            if (content.length()==0 && text.indexOf("wrap=\"virtual\"></textarea>")<0) {
                System.out.println("PAGE EXISTS!"); //Page is expected to be empty
                System.exit(0);
            }
            if (text.indexOf("<strong>Masz <a href=\"/wiki/Dyskusja_wikipedysty:Olafbot\"")>=0) {
                System.out.println("STOPPED!"); //Somebody terminated the process
                System.exit(0);
            }
            if (text.toLowerCase().indexOf("konflikt edycji")>=0) {
                System.out.println("CONFLICT!"); //Edition conflict
                System.exit(0);
            }
        } finally {
            if (socket!=null)
                socket.close();
        }
    }
    
    //Adding redirect
    static void addRedirect(String from,String to) throws Exception {
        System.out.println("reading "+from);
        connect(
            "GET /w/wiki.phtml?title="+from+"&action=edit HTTP/1.1\n"+
            "Content-type: application/x-www-form-urlencoded\n",
            ""
        );

        System.out.println("writing "+from);
        String content=
            "wpSummary=robot added: przekierowanie na "+to+"&"+
            //"+a+c+e+l+o+s+x+z+A+C+E+L+O+S+X+Z+"&"+
            "wpMinoredit=1&"+
            "wpTextbox1=#REDIRECT [["+to+"]]"+
            "\n";
        connect(
            "POST /w/wiki.phtml?title="+from+"&action=submit HTTP/1.1\n"+
            "Content-Type: application/x-www-form-urlencoded\n"+
            "Content-Length: "+String.valueOf(content.length())+"\n",
            content
        );

        System.out.println("successful");
    }
    
    public static void main(String[] args) throws Exception {
        final String monthsNames[]={
            "stycznia",
            "lutego",
            "marca",
            "kwietnia",
            "maja",
            "czerwca",
            "lipca",
            "sierpnia",
            "wrze"+s+"nia",
            "pa"+x+"dziernika",
            "listopada",
            "grudnia"
        };

        final String romanNumbers[]={"I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII"};

        final int monthsLengths[]={31,29,31,30,31,30,31,31,30,31,30,31};

        for (int m=0;m<12;m++)
            for (int d=1;d<=monthsLengths[m];d++) {
                addRedirect(String.valueOf(d)+"_"+romanNumbers[m],String.valueOf(d)+" "+monthsNames[m]);
                System.out.println("sleeping...");
                Thread.sleep(30000); //in milliseconds
            }
    }
}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Kembali kehalaman sebelumnya