Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SCRIPT_NAME = "wiki";
- import java.util.regex.*;
- Pattern title = Pattern.compile("\\s*\\[title\\] => (.*)$");
- Pattern missing = Pattern.compile("\\s*\\[missing\\] => .*$");
- print(String text)
- {
- clientGUI.printText("general","## ","41A317");
- clientGUI.printText("general", text +"\n");
- }
- run()
- {
- if (argument == null || ("".equals(argument))) return;
- String search = argument.replace(' ','_');
- int state = 0;
- try {
- print("search for " + search);
- URL url = new URL("http://batwiki.wx.fi/w/api.php?action=query&titles=" + search +"&prop=revisions&rvprop=content&format=txt&redirects");
- InputStream is = url.openStream();
- BufferedReader in = new BufferedReader(new InputStreamReader(is));
- String inputLine;
- while ((inputLine = in.readLine()) != null)
- {
- switch(state)
- {
- case 0:
- Matcher m = title.matcher(inputLine);
- if(m.matches())
- {
- print(m.group(1));
- state++;
- }
- break;
- case 1:
- if(inputLine.startsWith("|"))
- {
- print(inputLine);
- state++;
- } else if ((missing.matcher(inputLine)).matches())
- {
- print("was sadly not found on the wiki");
- }
- break;
- case 2:
- if(inputLine.startsWith("}}"))
- state++;
- else
- print(inputLine.replaceAll("\\[\\[","").replaceAll("\\]\\]",""));
- break;
- }
- //DEBUG
- //System.out.println(inputLine);
- }
- in.close();
- } catch (Exception e)
- {
- print("and we fail..");
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment