当前位置: 首页>>代码示例>>Python>>正文


Python Email.postgres_filename方法代码示例

本文整理汇总了Python中models.Email.postgres_filename方法的典型用法代码示例。如果您正苦于以下问题:Python Email.postgres_filename方法的具体用法?Python Email.postgres_filename怎么用?Python Email.postgres_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Email的用法示例。


在下文中一共展示了Email.postgres_filename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: walk_domain

# 需要导入模块: from models import Email [as 别名]
# 或者: from models.Email import postgres_filename [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.postgres_filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。