Advertisement
LegarsStyler

Untitled

Jan 9th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. package net.redheademile.matt;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.net.URL;
  9. import java.nio.channels.Channels;
  10. import java.nio.channels.ReadableByteChannel;
  11. import java.util.ArrayList;
  12.  
  13. public class Matt
  14. {
  15. public static void main(String[] args)
  16. {
  17. new Matt();
  18. }
  19.  
  20. public Matt()
  21. {
  22. File folder = new File("C:\\Users\\emili\\Documents\\kamek");
  23. int increment = 50, count = 0;
  24. for(int i = 0; i < 900; i += increment)
  25. {
  26. try
  27. {
  28. String content = savePage("https://git.wuffs.org/kamek/log/?h=resurrection&ofs="+Integer.toString(i));
  29. String[] result = getBeetween(content, "href='", "'>");
  30. for(int j = 0; j < result.length; j++)
  31. {
  32. if(result[j].contains("commit/") && result[j].contains("id="))
  33. {
  34. count++;
  35. String id = result[j].split("id=")[1];
  36. String url = "https://git.wuffs.org/kamek/snapshot/kamek-"+id+".zip";
  37.  
  38. URL website = new URL(url);
  39. ReadableByteChannel rbc = Channels.newChannel(website.openStream());
  40. FileOutputStream fos = new FileOutputStream(new File(folder, "kamek-"+id+".zip"));
  41. fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
  42. fos.close();
  43. rbc.close();
  44.  
  45. System.out.println(count + "/ 893 (supposé)");
  46. }
  47. }
  48. }
  49. catch(IOException e)
  50. {
  51. System.out.println("Erreur sur la page "+Integer.toString(i));
  52. }
  53. }
  54. }
  55.  
  56. public String[] getBeetween(String str, String behind, String front)
  57. {
  58. ArrayList<String> words = new ArrayList<>();
  59. for(String str_ : str.split(behind))
  60. {
  61. try
  62. {
  63. if(str_.contains(front))
  64. {
  65. //System.out.println(str_);
  66. words.add(str_.split(front)[0]);
  67. }
  68. }
  69. catch(Exception e) {}
  70. }
  71. return words.toArray(new String[words.size()]);
  72. }
  73.  
  74. public String savePage(final String URL) throws IOException
  75. {
  76. String line = "", all = "";
  77. URL myUrl = null;
  78. BufferedReader in = null;
  79. try {
  80. myUrl = new URL(URL);
  81. in = new BufferedReader(new InputStreamReader(myUrl.openStream()));
  82.  
  83. while ((line = in.readLine()) != null) all += line;
  84. }
  85. finally
  86. {
  87. if (in != null) in.close();
  88. }
  89.  
  90. return all;
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement