+ /**
+ * Records interesting shows.
+ * @param aProgramCondition Condition determining which shows are interesting.
+ * @param aGuide Television guide.
+ * @throws MessagingException In case of problems sending a summary mail.
+ */
+ private void recordInterestingShows(Condition<Program> aProgramCondition,
+ TVGuide aGuide) throws MessagingException {
+ MatchVisitor matcher = new MatchVisitor(aProgramCondition);
+ aGuide.accept(matcher);
+ List<Program> programs = matcher.getMatches();
+ String recorded = "";
+ String notRecorded = "";
+ String failures = "";
+ for (Program program : programs) {
+ try {
+ boolean result = program.record();
+ if (result) {
+ recorded += "\n" + program;
+ } else {
+ notRecorded += "\n" + program;
+ }
+ } catch (PageException e) {
+ LOG.info("Attempt to record " + program + " failed.");
+ failures += "\n" + program.toString() + ": " + e.getMessage();
+ }
+ }
+ String msg = "Summary of KiSS crawler: \n\n\n";
+
+ if (recorded.length() > 0) {
+ msg += "Recorded programs:\n\n" + recorded + "\n\n";
+ }
+ if (notRecorded.length() > 0) {
+ msg += "Not recorded programs:\n\n" + notRecorded + "\n\n";
+ }
+ if (recorded.length() == 0 && notRecorded.length() == 0) {
+ msg += "No suitable programs found";
+ }
+ if (failures.length() > 0) {
+ msg += "Failures:\n\n" + failures;
+ }
+ System.out.println(msg);
+ sendMail(msg);
+ }
+
+ /**
+ * Creates the crawler.
+ * @param aCrawlerConfig Crawler configuration file.
+ * @param aOs Logging output stream for the crawler.
+ * @param aClient HTTP Client to use.
+ * @return Crawler.
+ * @throws FileNotFoundException In case configuration files cannot be found.
+ */
+ private Crawler createCrawler(String aCrawlerConfig, PrintStream aOs,
+ HttpClient aClient) throws FileNotFoundException {
+ ConfigurationParser parser = new ConfigurationParser(aOs);
+ InputStream crawlerConfigFile = new FileInputStream(new File(
+ aCrawlerConfig));
+ Configuration config = parser.parse(crawlerConfigFile);
+ Crawler crawler = new CrawlerImpl(aClient, config);
+ return crawler;