예제 #1
0
    def close_spider(self, spider):
        subject = 'Image Scraper Report for ' + datetime.date.today().strftime("%m/%d/%y")
        from_email = "*****@*****.**"
        to_email = "*****@*****.**"
        msg = MIMEMultipart()
        msg['From'] = from_email
        msg['To'] = to_email
        msg['Subject'] = subject
        intro = "Summary stats from Scrapy spider: \n\n"
        body = spider.crawler.stats.get_stats()
        body = pprint.pformat(body)
        body = intro + body
        msg.attach(MIMEText(body, 'plain'))

        mailer = MailSender()
        text = msg.as_string()
        mailer.send(to=[to_email], subject=subject, body=text)
        mailer.quit()