private static void initializeCrawler(Crawler crawler, String[] args) { try { CommandLineHelper cmdHelper = new CommandLineHelper(Crawler.class); cmdHelper.parse(args); crawler.setCmdHelper(cmdHelper); CommandLine cli = cmdHelper.getParsedCmdLine(); if (args.length == 0 || cli.hasOption("h")) { cmdHelper.displayHelp(); return; } FacebookConnectionManager connectionManager = null; if (cli.hasOption("k")) { String ACCESS_KEY = (String) cmdHelper.getOptionValue("k"); connectionManager = new FacebookConnectionManager(ACCESS_KEY); } else throw new Exception("Must provide -k argument"); crawler.setConnectionManager(connectionManager); PrintStream output = System.out; output = new PrintStream(new FileOutputStream("OutPut.txt")); // if(cli.hasOption("o")) { // output = new PrintStream(new // FileOutputStream((String)cmdHelper.getOptionValue("o"))); // } crawler.setOutputStream(output); } catch (Exception e) { e.printStackTrace(); } }
private boolean crawlUsers() { CommandLine cli = cmdHelper.getParsedCmdLine(); List<String> usersToCrawl = new ArrayList<String>(); if (cli.hasOption("uc")) usersToCrawl.add((String) cmdHelper.getOptionValue("uc")); else if (cli.hasOption("ul")) { String fileName = (String) cmdHelper.getOptionValue( "ul"); // This line is only there to check if we are getting the file name // correctly FileUtil.loadFile("UserIDs", usersToCrawl); } else return false; // Note: This is not efficient. Substitute later with thread pools. for (String userID : usersToCrawl) { FacebookClient facebookclient = connectionManager.getFacebookClient(); UserInfo info = getUserInfo(userID); info.dump(outputStream); } return true; }