當前位置: 首頁>>代碼示例>>Python>>正文


Python Email.domain方法代碼示例

本文整理匯總了Python中models.Email.domain方法的典型用法代碼示例。如果您正苦於以下問題:Python Email.domain方法的具體用法?Python Email.domain怎麽用?Python Email.domain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Email的用法示例。


在下文中一共展示了Email.domain方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: walk_domain

# 需要導入模塊: from models import Email [as 別名]
# 或者: from models.Email import domain [as 別名]
def walk_domain(domain, path):
    new_path = os.path.join(path, 'new')
    email_filenames = os.listdir(new_path)
    email_count = len(email_filenames)
    print 'Reading %s, %d emails.' % (domain, email_count)
    for i, email_filename in enumerate(email_filenames):
        email_filepath = os.path.join(new_path, email_filename)

        try:
            message = Parser().parse(open(email_filepath, 'r'))
            email = Email()
            email.domain = domain
            email.header_from = message['from']
            email.header_to = message['to']
            email.header_subject = message['subject']
            email.header_date = parser.parse(message['date'])

            email.postgres_filename = email_filename
            email.original = message.as_string()

            session.add(email)
            session.commit()

            cur_path = os.path.join(path, 'cur')
            os.rename(email_filepath, os.path.join(cur_path, email_filename))

        except Exception, exc:
            print exc

            fail_path = os.path.join(path, 'fail')
            if not os.path.exists(fail_path):
                os.makedirs(fail_path)

            os.rename(email_filepath, os.path.join(fail_path, email_filename))

        stdout('\r%5d/%5d : %0.2f%%' % (i, email_count, i * 100.0 / email_count))
開發者ID:chbrown,項目名稱:fixgres,代碼行數:38,代碼來源:work.py


注:本文中的models.Email.domain方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。