How to sort / filter Google Code projects by stars?

I would like to know which projects are hosted on Google Code that have the most stars, especially when searching by tag, for example:

https://code.google.com/hosting/search?q=label%3aAndroid

+6
source share
2 answers

Star sorting is not supported on the project search page. I was able to write code to delete the page to get the necessary information.

Hope this helps.

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class ReadGoogleProjectSortByStars { public static void main(String[] args) throws IOException { String urlPath = "https://code.google.com/hosting/search?q=label%3AAndroid&filter=0&mode=&start="; // urlPath = "https://code.google.com/hosting/search?q=label%3AAndroid+stackoverflow&projectsearch=Search+projects&filter=0&mode=&start="; int start = 0; List<Project> projects = new ArrayList<Project>(); boolean done = false; while(!done) { String urlStr = urlPath + start; URL url = new URL(urlStr); BufferedReader in = new BufferedReader( new InputStreamReader(url.openStream())); String inputLine; String projectUrl = null, stars = null; while ((inputLine = in.readLine()) != null) { int urlIndex = -1, starIndex = -1; if(inputLine.contains(" style=\"font-size:medium\">") && (urlIndex = inputLine.indexOf(" href=\"/p/")) != -1) { if(projectUrl != null) { Project project = new Project(); project.url = projectUrl; project.stars = "0"; projects.add(project); } String projectTempUrl = inputLine.substring(urlIndex + " href=\"/p/".length()); projectUrl = "https://code.google.com/p/" + projectTempUrl.substring(0, projectTempUrl.indexOf("\"")); } if((starIndex = inputLine.indexOf("id=\"star_count-")) != -1) { stars = inputLine.substring(inputLine.indexOf(">") + 1, inputLine.indexOf("</span>")); Project project = new Project(); project.url = projectUrl; project.stars = stars; projects.add(project); projectUrl = stars = null; } if(inputLine.contains(" - did not generate any results.")) { done = true; break; } } in.close(); start +=10; if(projectUrl != null) { Project project = new Project(); project.url = projectUrl; project.stars = "0"; projects.add(project); } } Collections.sort(projects, new Comparator<Project>() { @Override public int compare(Project project1, Project project2) { Integer stars1 = Integer.parseInt(project1.stars); Integer stars2 = Integer.parseInt(project2.stars); return -stars1.compareTo(stars2); } }); System.out.println("Total projects:" +projects.size()); for (Project project : projects) { System.out.println(project.url + ":" + project.stars); } } } class Project { String url; String stars; } 
+7
source

I would say use &sort=stars , as with google support, but it doesn’t work. I'm not sure if this is possible, unfortunately ...

0
source

Source: https://habr.com/ru/post/946154/


All Articles