Guest User

Untitled

a guest
Mar 22nd, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. SCRIPT_NAME = "wiki";
  2. import java.util.regex.*;
  3.  
  4. Pattern title = Pattern.compile("\\s*\\[title\\] => (.*)$");
  5. Pattern missing = Pattern.compile("\\s*\\[missing\\] => .*$");
  6.  
  7. print(String text)
  8. {
  9. clientGUI.printText("general","## ","41A317");
  10. clientGUI.printText("general", text +"\n");
  11. }
  12.  
  13. run()
  14. {
  15. if (argument == null || ("".equals(argument))) return;
  16. String search = argument.replace(' ','_');
  17. int state = 0;
  18.  
  19. try {
  20. print("search for " + search);
  21.  
  22. URL url = new URL("http://batwiki.wx.fi/w/api.php?action=query&titles=" + search +"&prop=revisions&rvprop=content&format=txt&redirects");
  23. InputStream is = url.openStream();
  24. BufferedReader in = new BufferedReader(new InputStreamReader(is));
  25. String inputLine;
  26.  
  27. while ((inputLine = in.readLine()) != null)
  28. {
  29. switch(state)
  30. {
  31. case 0:
  32. Matcher m = title.matcher(inputLine);
  33. if(m.matches())
  34. {
  35. print(m.group(1));
  36. state++;
  37. }
  38. break;
  39. case 1:
  40. if(inputLine.startsWith("|"))
  41. {
  42. print(inputLine);
  43. state++;
  44. } else if ((missing.matcher(inputLine)).matches())
  45. {
  46. print("was sadly not found on the wiki");
  47. }
  48. break;
  49. case 2:
  50. if(inputLine.startsWith("}}"))
  51. state++;
  52. else
  53. print(inputLine.replaceAll("\\[\\[","").replaceAll("\\]\\]",""));
  54. break;
  55. }
  56.  
  57.  
  58. //DEBUG
  59. //System.out.println(inputLine);
  60. }
  61. in.close();
  62.  
  63. } catch (Exception e)
  64. {
  65. print("and we fail..");
  66.  
  67. e.printStackTrace();
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment