Пример #1
0
 def _render_msg(self, date):
     filepath = Tools.get_filepath()
     content = open(filepath).read()
     msg = MIMEText(content, 'html', CONFIG.ENCODE)
     msg['Subject'] = '{0} {1}'.format(CONFIG.SUBJECT, date)
     msg['From'] = "%s <%s>" % (CONFIG.ME, CONFIG.FROM)
     msg['To'] = ','.join(CONFIG.TO)
     return msg
Пример #2
0
def run():
    CONFIG.load()
    date = Tools.get_date()
    crawler = Crawler()
    if crawler.start(date): 
        Mail().send_mail(date)
Пример #3
0
    def _parser(self, html):
        daily = html.find(class_='daily')
        date = daily.find(class_='date')

        data = [date.prettify(self.html_encode)]
        for post in daily.find_all(class_='post'):
            title = post.find(class_='title').a
            subject = post.find(class_='subject-name')
            if not subject.a['href'].startswith(self.base_url):
                subject.a['href'] = self.base_url + subject.a['href']

            data.append('<br />')
            data.append(title.prettify(self.html_encode))
            data.append(subject.prettify(self.html_encode))

        return data

    def _save(self, date, data):
        filename = date + '.html'
        filepath = self.path + filename

        with open(filepath, 'w') as f:
            f.write(''.join(data))


if __name__ == '__main__':
    CONFIG.load()
    date = Tools.get_date()
    Crawler().start(date)