Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.wikia.runescape;
- import org.mediawiki.MediaWiki;
- import org.w3c.dom.Document;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.NodeList;
- import java.io.*;
- import java.net.*;
- import java.util.Map;
- import java.util.TreeMap;
- public class AbuseFilterReader {
- public static void main(String[] args) throws IOException {
- // Which wiki are we working on?
- final MediaWiki wiki = new MediaWiki("runescape.wikia.com").setUsingCompression(true);
- while (true) {
- try {
- wiki.logIn("Gaz Lloyd", "ilovemol".toCharArray());
- break;
- } catch (final MediaWiki.LoginFailureException e) {
- System.err.println("Login failed; please check LoginName and LoginPassword in the configuration file");
- e.printStackTrace();
- System.exit(1);
- return;
- } catch (final MediaWiki.LoginDelayException t) {
- System.err.println("Login throttled; retrying in " + t.getWaitTime() + " seconds");
- try {
- Thread.sleep((long) t.getWaitTime() * 1000);
- } catch (InterruptedException e) {
- // don't care
- }
- } catch (final MediaWiki.BlockException b) {
- System.err.println("User blocked; please check its block log");
- b.printStackTrace();
- System.exit(1);
- return;
- } catch (IOException e) {
- System.err.println("Network error occurred while logging in; retrying shortly");
- e.printStackTrace();
- shortDelay();
- } catch (MediaWiki.MediaWikiException e) {
- System.err.println("Network error occurred while logging in; retrying shortly");
- e.printStackTrace();
- shortDelay();
- }
- }
- Map<String, String> params = new TreeMap<String, String>();
- params.put("format", "xml");
- params.put("action", "query");
- params.put("list", "abuselog");
- params.put("aflfilter", "45");
- params.put("aflprop", "details");
- params.put("afllimit", "50");
- //InputStream in = null;
- Document in = null;
- try {
- in = wiki.getABFLog(params);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- NodeList eles = in.getElementsByTagName("details");
- for (int i = 0; i < eles.getLength(); i++) {
- NamedNodeMap n = eles.item(i).getAttributes();
- System.out.println(parse2(n));
- }
- }
- public static String parse2(NamedNodeMap n) {
- String time = n.getNamedItem("timestamp").getNodeValue();
- String user = n.getNamedItem("user_name").getNodeValue();
- String article = n.getNamedItem("article_text").getNodeValue().replace("Feedback/", "");
- String txt = n.getNamedItem("new_wikitext").getNodeValue();
- txt = txt.replaceAll(""", "");
- txt = txt.replace("\"", "");
- String rating = txt.replaceAll(".*?\\{rating:(\\d),comment:(.*?)\\}.*?", "$1");
- String comment = txt.replaceAll(".*?\\{rating:(\\d),comment:(.*?)\\}.*?", "$2");
- return "[" + time + "]: " + user + " rated " + article + ": Rating: " + rating + "; Comment: " + comment;
- }
- public static String parse(String s) {
- int locDet = s.indexOf("new_wikitext=\"");
- int locDetEnd = s.indexOf("\"", locDet + 14);
- int locTitle = s.indexOf("article_text=\"");
- int locTitleEnd = s.indexOf("\"", locTitle + 14);
- int locTime = s.indexOf("timestamp=");
- int locTimeEnd = s.indexOf("\"", locTime + 11);
- String details = s.substring(locDet + 14, locDetEnd);
- details = details.replace(""", "\u7812");
- String title = s.substring(locTitle + 14, locTitleEnd);
- title = title.replace("Feedback/", "");
- String timestamp = s.substring(locTime + 11, locTimeEnd);
- int ratst = details.indexOf("rating") + 9;
- String rating = details.substring(ratst, ratst + 1);
- int comst = details.indexOf("comment") + 9;
- int comend = details.indexOf('\u7812', comst + 1);
- String comment = details.substring(comst + 1, comend);
- comment = comment.trim().replace("\\n", "<br>");
- comment = comment.replaceAll("(.)\\1{5,}", "$1[trimmed]");
- return "|-\n| [[" + title + "]] || {{subst:#time:d&\\n\\b\\s\\p;F; H:i|January 1 1970 00:00:00 + " + timestamp + "seconds}} || " + rating + " || " + comment;
- }
- private static void shortDelay() {
- try {
- Thread.sleep(45000);
- } catch (final InterruptedException e) {
- // don't care
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement