From dbb0ee9cc1d8004ee4d8ad77678e1f396880d784 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 21 Mar 2006 21:31:37 +0000 Subject: [PATCH] --- crawler/kiss/conf/kiss/programs.xml | 2 +- .../crawler/kiss/main/KissCrawler.java | 63 +------------------ .../crawler/kiss/main/ProgramAction.java | 4 +- .../kiss/main/ProgramActionExecutor.java | 41 +----------- .../kiss/notification/MailNotifier.java | 4 -- 5 files changed, 5 insertions(+), 109 deletions(-) diff --git a/crawler/kiss/conf/kiss/programs.xml b/crawler/kiss/conf/kiss/programs.xml index fabc9fbc..82de82fa 100644 --- a/crawler/kiss/conf/kiss/programs.xml +++ b/crawler/kiss/conf/kiss/programs.xml @@ -36,7 +36,7 @@ documentaires notify - (zembla)|(uur.*wolf) + (zembla)|(uur.*wolf)|(andere tijden) diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/main/KissCrawler.java b/crawler/kiss/src/org/wamblee/crawler/kiss/main/KissCrawler.java index 6cdaa17a..5d7e85ca 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/main/KissCrawler.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/main/KissCrawler.java @@ -16,7 +16,6 @@ package org.wamblee.crawler.kiss.main; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -25,26 +24,15 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; import java.util.List; -import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.internet.InternetAddress; -import javax.xml.transform.TransformerException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.mail.EmailException; -import org.apache.commons.mail.HtmlEmail; -import org.apache.xml.serialize.OutputFormat; -import org.apache.xml.serialize.XMLSerializer; -import org.w3c.dom.Document; import org.wamblee.crawler.Action; import org.wamblee.crawler.Configuration; import org.wamblee.crawler.Crawler; @@ -60,8 +48,6 @@ import org.wamblee.crawler.kiss.guide.Time; import org.wamblee.crawler.kiss.guide.TimeInterval; import org.wamblee.crawler.kiss.notification.NotificationException; import org.wamblee.crawler.kiss.notification.Notifier; -import org.wamblee.io.FileResource; -import org.wamblee.xml.XSLT; /** * The KiSS crawler for automatic recording of interesting TV shows. @@ -183,7 +169,7 @@ public class KissCrawler { } executor.commit(); try { - aNotifier.send(executor.getXmlReport()); + aNotifier.send(executor.getReport()); } catch (NotificationException e) { throw new RuntimeException(e); } @@ -306,51 +292,4 @@ public class KissCrawler { } return new Channel(aChannel, programs); } - - /** - * Sends a summary mail to the user. - * - * @param aText - * Text of the mail. - * @throws MessagingException - * In case of problems sending mail. - */ - private void sendMail(ProgramActionExecutor aExecutor) throws MessagingException { - String textReport = aExecutor.getReport(); - System.out.println("Text report: \n" + textReport); - System.out.println("XML report:\n" + aExecutor.getXmlReport().asXML()); - - - Properties props = new Properties(); - props.put("mail.transport.protocol", "smtp"); - props.put("mail.smtp.host", "falcon"); - props.put("mail.smtp.port", "25"); - - Session mailSession = Session.getInstance(props); - InternetAddress from = new InternetAddress("erik@brakkee.org"); - - HtmlEmail mail = new HtmlEmail(); - mail.setMailSession(mailSession); - try { - mail.setFrom("erik@brakkee.org"); - mail.setTo(Arrays.asList(new InternetAddress[] { from })); - mail.setSentDate(new Date()); - mail.setSubject("KiSS Crawler Update"); - String html = aExecutor.getXmlReport().asXML(); - Document document = new XSLT().transform(html.getBytes(), new FileResource(new File("reportToHtml.xsl"))); - ByteArrayOutputStream xhtml = new ByteArrayOutputStream(); - XMLSerializer serializer = new XMLSerializer(xhtml, new OutputFormat()); - serializer.serialize(document); - mail.setHtmlMsg(xhtml.toString()); - mail.setTextMsg(textReport); - mail.send(); - } catch (EmailException e) { - throw new RuntimeException(e); - } catch (TransformerException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramAction.java b/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramAction.java index d67c26d1..e9d3bcbe 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramAction.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramAction.java @@ -26,7 +26,7 @@ public interface ProgramAction { /** * Executes the action. * @param aProgram Program to execute the action for. - * @param aReport Report to use. + * @param aExecutor Report to use. */ - void execute(Program aProgram, ProgramActionExecutor aReport); + void execute(Program aProgram, ProgramActionExecutor aExecutor); } diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java b/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java index 3ef511cf..27297a6f 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java @@ -99,50 +99,11 @@ public class ProgramActionExecutor { } } - /** - * Gets the report describing what was done. - * @return Report. - */ - public String getReport() { - StringBuffer msg = new StringBuffer("Summary of KiSS crawler: \n\n\n"); - - boolean printed = false; - - for (RecordingResult result : RecordingResult.values()) { - if (_recordings.get(result).size() > 0) { - msg.append(result.getDescription() + "\n\n"); - for (Program program : _recordings.get(result)) { - msg.append(program + "\n\n"); - printed = true; - } - } - } - - if ( _interestingShows.size() > 0 ) { - msg.append("Possibly interesting shows:\n\n"); - for (String category: _interestingShows.keySet()) { - if ( category.length() > 0 ) { - msg.append("Category: " + category + "\n\n"); - } - for (Program program: _interestingShows.get(category)) { - msg.append(program + "\n\n"); - printed = true; - } - } - - } - if (!printed) { - msg.append("No suitable programs found"); - } - - return msg.toString(); - } - /** * Get report as XML. * @return XML report */ - public Element getXmlReport() { + public Element getReport() { DocumentFactory factory = DocumentFactory.getInstance(); Element report = factory.createElement("report"); diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/notification/MailNotifier.java b/crawler/kiss/src/org/wamblee/crawler/kiss/notification/MailNotifier.java index 1c970a71..47c3edd5 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/notification/MailNotifier.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/notification/MailNotifier.java @@ -4,7 +4,6 @@ */ package org.wamblee.crawler.kiss.notification; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -16,10 +15,7 @@ import javax.xml.transform.TransformerException; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; -import org.apache.xml.serialize.OutputFormat; -import org.apache.xml.serialize.XMLSerializer; import org.dom4j.Element; -import org.w3c.dom.Document; import org.wamblee.io.FileResource; import org.wamblee.io.InputResource; import org.wamblee.xml.XSLT; -- 2.31.1