fork download
  1. package userfinder;
  2.  
  3. import com.sun.deploy.util.StringUtils;
  4.  
  5. import java.io.*;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.util.*;
  9.  
  10. public class FindUserByGroups {
  11. private static final int USERS_PEER_PAGE = 1000;
  12. private final static String SORT_TYPE = "id_desc";
  13. private static int TOTAL_ITERATIONS_COUNT;
  14. private static int totalIterationsCount = 0;
  15. private static int GROUPS_COUNT = 0;
  16. private static List<String> AllIDs = new ArrayList<>();
  17. private static int percent = -1;
  18.  
  19. public static void main(String[] args) throws Exception {
  20. System.out.println("List the each public links at new line or public IDs separated by commas: ");
  21. StringBuilder ids = new StringBuilder(reader.readLine());
  22. while (ids.indexOf("\u0020") != -1)
  23. ids.deleteCharAt(ids.indexOf("\u0020"));
  24. String publicIDs[];
  25. if (ids.indexOf("vk.com") != -1) {
  26. ArrayList<String> links = new ArrayList<>();
  27. while (true) {
  28. StringBuilder read = new StringBuilder(reader.readLine());
  29. while (read.indexOf("\u0020") != -1)
  30. read.deleteCharAt(read.indexOf("\u0020"));
  31. if (read.toString().isEmpty())
  32. break;
  33. links.add(read.substring(read.indexOf("vk.com/") + 7, read.length()));
  34. }
  35. links.add(ids.substring(ids.indexOf("vk.com/") + 7, ids.length()));
  36. publicIDs = new String[links.size()];
  37. for (int i = 0; i < publicIDs.length; i++) {
  38. publicIDs[i] = links.get(i);
  39. }
  40. } else {
  41. String[] idsSplitted = StringUtils.splitString(ids.toString(), "\u002c");
  42. publicIDs = new String[idsSplitted.length];
  43. for (int i = 0; i < idsSplitted.length; i++) {
  44. try {
  45. if (idsSplitted[i].contains("id") || idsSplitted[i].contains("ID")) {
  46. publicIDs[i] = idsSplitted[i].substring(2, idsSplitted[i].length());
  47. continue;
  48. }
  49. publicIDs[i] = idsSplitted[i];
  50. } catch (NumberFormatException e) {
  51. System.out.println("The value \"" + idsSplitted[i] + "\" is not a valid and it has not been considered.");
  52. }
  53. }
  54.  
  55. if (publicIDs.length == 1 && publicIDs[0] == null) {
  56. throw new RuntimeException("No correct IDs");
  57. }
  58. if (publicIDs.length <= 1) {
  59. throw new RuntimeException("You should list 2 or more public IDs");
  60. }
  61. }
  62.  
  63. System.out.print("Publics: ");
  64. for (String publicID : publicIDs) {
  65. if (publicID != null)
  66. System.out.print("\"" + publicID + "\" ");
  67. }
  68. System.out.println("accepted.");
  69. System.out.println("******************************************\n\n");
  70. for (String publicID : publicIDs) {
  71. TOTAL_ITERATIONS_COUNT += getMembersCount(publicID, false) / 1000;
  72. }
  73. TOTAL_ITERATIONS_COUNT--;
  74. for (String publicID : publicIDs) {
  75. if (publicID != null) {
  76. processPublic(publicID);
  77. GROUPS_COUNT++;
  78. }
  79. }
  80. System.out.println("******************************************");
  81. findMatches();
  82. }
  83.  
  84. private static void findMatches() {
  85. System.out.println("Finding matches...");
  86. boolean mFound = false;
  87. Collections.sort(AllIDs);
  88. int m = 1;
  89. int f = 0;
  90. for (int i = 1; i < AllIDs.size(); i++) {
  91. if (AllIDs.get(i - 1).equals(AllIDs.get(i))) {
  92. m++;
  93. } else if (m >= GROUPS_COUNT) {
  94. System.out.println("# match found: http://content-available-to-author-only.com/id" + (AllIDs.get(i - 1).contains("\n") ?
  95. AllIDs.get(i - 1).substring(1, AllIDs.get(i - 1).length()) : AllIDs.get(i - 1)));
  96. mFound = true;
  97. m = 1;
  98. f++;
  99. } else m = 1;
  100. }
  101. if (!mFound)
  102. System.out.println("No matches found.");
  103. else System.out.println("Total matches found: " + f);
  104. }
  105.  
  106. private static void processPublic(String publicID) {
  107. System.out.println("# processing public " + publicID + "...");
  108. SaveUserIdsToList(publicID);
  109. System.out.println("");
  110. }
  111.  
  112. private static int getMembersCount(String publicID, boolean show) {
  113. int mCount;
  114. String s = getJSON("https://a...content-available-to-author-only...k.com/method/groups.getById?group_id=" + publicID + "&fields=members_count");
  115. int cPos = 0;
  116. for (int i = s.indexOf("\"members_count\":"); i < s.length(); i++) {
  117. try {
  118. if (s.charAt(i) == ',') {
  119. cPos = i;
  120. break;
  121. }
  122. System.out.println("Processing public " + publicID + " caused an error.");
  123. }
  124. }
  125. mCount = Integer.parseInt(s.substring(s.indexOf("\"members_count\":") + 16, cPos));
  126. if (show) System.out.println("# members in " + publicID + ": " + mCount);
  127. return mCount;
  128. }
  129.  
  130.  
  131. private static void SaveUserIdsToList(String publicID) {
  132. int membersCount = getMembersCount(publicID, true);
  133. final int iterCount = membersCount / 1000 + 1;
  134. System.out.println("# iterations required: " + iterCount);
  135. for (int i = 0; i < iterCount; i++) {
  136. StringBuilder g = new StringBuilder(getJSON("https://a...content-available-to-author-only...k.com/method/groups.getMembers?group_id=" + publicID + "&offset=" + (i * USERS_PEER_PAGE) + "&sort=" + SORT_TYPE));
  137. g.delete(0, g.indexOf("\"users\":[") + 9);
  138. g.delete(g.length() - 3, g.length());
  139. totalIterationsCount++;
  140. int curP = (int) Math.floor(totalIterationsCount * 1.0 / TOTAL_ITERATIONS_COUNT * 100);
  141. if (curP > percent && curP <= 100) {
  142. System.out.println("# progress: " + curP + "%");
  143. percent = curP;
  144. }
  145. String[] splitted = StringUtils.splitString(g.toString().replace("\u002c", "\u002c\n"), "\u002c");
  146. for (String aSplitted : splitted) {
  147. try {
  148. AllIDs.add(aSplitted);
  149. } catch (NumberFormatException e) {
  150. System.out.println("# wrong number format: " + aSplitted);
  151. }
  152. }
  153. }
  154. }
  155.  
  156. private static String getJSON(String url) {
  157. URLConnection connection = null;
  158. try {
  159. connection = new URL(url).openConnection();
  160. } catch (IOException e) {
  161. e.printStackTrace();
  162. }
  163.  
  164. InputStream is = null;
  165. try {
  166. is = connection.getInputStream();
  167. } catch (IOException e) {
  168. e.printStackTrace();
  169. }
  170. char[] buffer = new char[256];
  171. int rc;
  172.  
  173. StringBuilder sb = new StringBuilder();
  174.  
  175. try {
  176. while ((rc = reader.read(buffer)) != -1)
  177. sb.append(buffer, 0, rc);
  178. } catch (IOException e) {
  179. e.printStackTrace();
  180. }
  181.  
  182. try {
  183. reader.close();
  184. } catch (IOException e) {
  185. e.printStackTrace();
  186. }
  187.  
  188. return sb.toString();
  189. }
  190. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:10: error: class FindUserByGroups is public, should be declared in a file named FindUserByGroups.java
public class FindUserByGroups {
       ^
Main.java:3: error: package com.sun.deploy.util does not exist
import com.sun.deploy.util.StringUtils;
                          ^
Main.java:42: error: cannot find symbol
            String[] idsSplitted = StringUtils.splitString(ids.toString(), "\u002c");
                                   ^
  symbol:   variable StringUtils
  location: class FindUserByGroups
Main.java:147: error: cannot find symbol
            String[] splitted = StringUtils.splitString(g.toString().replace("\u002c", "\u002c\n"), "\u002c");
                                ^
  symbol:   variable StringUtils
  location: class FindUserByGroups
4 errors
stdout
Standard output is empty