@Nullable public List<String> getPyPIListFromWeb() { return HttpRequests.request(PYPI_LIST_URL) .connect( new HttpRequests.RequestProcessor<List<String>>() { @Override public List<String> process(@NotNull HttpRequests.Request request) throws IOException { final List<String> packages = new ArrayList<String>(); Reader reader = request.getReader(); new ParserDelegator() .parse( reader, new HTMLEditorKit.ParserCallback() { boolean inTable = false; @Override public void handleStartTag(HTML.Tag tag, MutableAttributeSet set, int i) { if ("table".equals(tag.toString())) { inTable = !inTable; } if (inTable && "a".equals(tag.toString())) { packages.add(String.valueOf(set.getAttribute(HTML.Attribute.HREF))); } } @Override public void handleEndTag(HTML.Tag tag, int i) { if ("table".equals(tag.toString())) { inTable = !inTable; } } }, true); return packages; } }, Collections.<String>emptyList(), LOG); }
public Collection<String> getPackageNames() { Map<String, String> pyPIPackages = getPyPIPackages(); ArrayList<String> list = Lists.newArrayList(pyPIPackages.keySet()); Collections.sort(list); return list; }