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


Python Gmail.authenticate方法代码示例

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


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

示例1: authenticate

# 需要导入模块: from gmail import Gmail [as 别名]
# 或者: from gmail.Gmail import authenticate [as 别名]
def authenticate(username, access_token):
    gmail = Gmail()
    gmail.authenticate(username, access_token)
    return gmail
开发者ID:jeekl,项目名称:gmail,代码行数:6,代码来源:utils.py

示例2: calculate_email_stats

# 需要导入模块: from gmail import Gmail [as 别名]
# 或者: from gmail.Gmail import authenticate [as 别名]
def calculate_email_stats(
    USERNAME,
    ACCESS_TOKEN,
    DAYS,
    ALIASES=[],
    IGNORE_EMAILS=[],
    IGNORE_SUBJECT_KEYWORDS=[],
    IGNORE_BODY_KEYWORDS=[],
    MIN_THREAD_LENGTH=0,
    ):
    """
    Calculate a bunch of stats and return a dict of values for rendering.
    """

    ALIASES.append(USERNAME)
    # Log in to Gmail
    g = Gmail()
    g.authenticate(USERNAME, ACCESS_TOKEN)

    write( "Login success!")

    # Pull all emails
    now = datetime.datetime.now()
    after = now - datetime.timedelta(days=DAYS)
    emails = g.all_mail().mail(
                prefetch=True,
                after = after,
             )
    total_email_count = len(emails)
    write("Retrieved %s emails." % total_email_count)

    # Clean emails
    could_not_fetch = [email for email in emails if not email.body]
    emails = [email for email in emails if email.body]

    no_thread_id = [email for email in emails if not email.thread_id]
    emails = [email for email in emails if email.thread_id]

    ignored_for_email = [email for email in emails if \
                             (email_in_aliases(email.fr, IGNORE_EMAILS) or \
                              email_in_aliases(email.to, IGNORE_EMAILS))]
    emails            = [email for email in emails if \
                         not (email_in_aliases(email.fr, IGNORE_EMAILS) or \
                              email_in_aliases(email.to, IGNORE_EMAILS))]

    ignored_for_subject = [email for email in emails if \
                           email_in_aliases(
                               email.subject,
                               IGNORE_SUBJECT_KEYWORDS)]
    emails              = [email for email in emails if \
                           not email_in_aliases(
                               email.subject,
                               IGNORE_SUBJECT_KEYWORDS)]

    ignored_for_body    = [email for email in emails if \
                           email_in_aliases(
                               email.body,
                               IGNORE_BODY_KEYWORDS)]
    emails              = [email for email in emails if \
                           not email_in_aliases(
                               email.body,
                               IGNORE_BODY_KEYWORDS)]

    write("Finished grabbing emails")

    # Group emails by thread
    threads = {}

    for email in emails:
        if not email.thread_id in threads.keys():
            threads[email.thread_id] = []
        threads[email.thread_id].append(email)

    write("Removed bad emails")

    # Sort and pull off the last responder
    last_responder_was_me = []
    last_responder_was_counterparty = []
    selfies = []
    only_sender_was_me = []

    for key in threads.keys():
        thread = threads[key]
        #if len(thread) > 5:
        #    import ipdb;
        #    ipdb.set_trace()
        thread.sort(cmp=lambda x,y:cmp(x.sent_at, y.sent_at), reverse=True)
        conversation = Conversation(thread)
        last_email = conversation.last_email

        # import ipdb
        # if "rentapp" in last_email.fr and "rentapp" in last_email.to:
        #     ipdb.set_trace()
        # I wrote it to someone other than me
        if (email_in_aliases(last_email.fr, ALIASES) and \
            not email_in_aliases(last_email.to, ALIASES)):
            last_responder_was_me.append(conversation)
        # I wrote it to myself
        elif (email_in_aliases(last_email.fr, ALIASES) and \
              email_in_aliases(last_email.to, ALIASES)):
#.........这里部分代码省略.........
开发者ID:ezl,项目名称:gmailstats,代码行数:103,代码来源:calculate_email_stats.py


注:本文中的gmail.Gmail.authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。