Exemplo n.º 1
0
def main():
    temp_file = os.path.sep + 'data ' + os.path.sep + 'log' + os.path.sep + 'item' + os.path.sep +'root.log'
    la = LogAnalyse(temp_file)
    error_log = open('error.log', 'w')
    a = ''
    for k, v in la.get_error_counts().items():
        error_log.write(k.strip('\n').decode("utf8") + "出现次数:" + str(v) + '\n')
        a = a + k.strip('\n').decode("utf8") + "出现次数:" + str(v) + '\n'
    
    tempList = la.get_latest_log(5)

    # 初始化发送邮件类
    sml = SendMail(EMAIL_USER, EMAIL_PASSWORD, EMAIL_HOST)
    # 设置邮件信息
    text_type = 'plain'
    sml.setMailInfo(TO_EMAIL, EMAIL_HEADER, a, text_type, os.getcwd() + os.path.sep + 'error.log')
    sml.sendMail()
    for i in tempList:
        if 'Disconnected' in i:
            sml.reinitMailInfo()
            sml.setMailInfo(TO_EMAIL, "zookeeper挂了", "zookeeper又尼玛挂了,赶紧去看看啊!!!", text_type)
            sml.sendMail()
            break
    error_log.close()
Exemplo n.º 2
0
                        fp.write(link + "\r\n")
                        fp.write(page["title"])
                        fp.write(page["content"])
                        print link
                else:
                    print "login failed"
            elif o in ("-m", "--mail"):
                from mail import SendMail

                db    = CrawlDB()
                mail = SendMail()
                # search db
                pages = db.getPages()
                if pages:
                    for page in pages:
                        if mail.sendMail(page["title"], page["content"]):
                            db.setUrl(page["url"])
                else:
                    print "no mail is sent"
                mail.close()
            else:
                assert False, "unhandled option"
    else:
        # from time import strftime, gmtime
        # timefmt = strftime("%y-%m-%d", gmtime())
        # print "%s run crawl.crawlPages()" % (timefmt)

        crawl.crawlPages()

if __name__ == "__main__":
    main()