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


Python Message.extractRecipients方法代码示例

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


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

示例1: main

# 需要导入模块: import Message [as 别名]
# 或者: from Message import extractRecipients [as 别名]
def main():

    # 0. Register the application to Parse

    registerToParse()

    # 1. set up time format
    d = datetime.datetime.utcnow()

    # 2. Get Authorization

    t0 = calendar.timegm(d.utctimetuple())
    
    # Local
    if SERVER == False:
        service = getAuthPython('client_secret.json')
    elif SERVER == True:
        service = getAuthPythonFromString(sys.argv[1])

    # Server
    #service = getAuthPythonFromString(sys.argv[1])

    # 3. Get Query
    # query_all = getQuery(NUM_DAYS, 'all')


    # 4. Run the query

    user = "me" # Use the user who authorized the call
    userName = getUserEmail(service[1])


    # 4.5 Check whether we have the user in the database

    # Check if user already had his mailbox processed:
    userEntries = UserEntry.Query.filter(uemail = userName)

    if len(userEntries) == 0:
        print "User logging in for the first time, creating a database entry on Parse"
        
        userEntry = UserEntry(uemail = userName, userCreated=t0, lastLogin=t0, 
            mailboxProcessed=False, lastMailboxUpdate=t0, numAppOpened=1)

        userEntry.save()
    
    elif len(userEntries) == 1:
        print "User found - updating access statistics"

        userEntry = userEntries[0]
        userEntry.increment("numAppOpened")
        userEntry.lastLogin = t0

        userEntry.save()

        if userEntry.mailboxProcessed == True:
            print "User's mailbox already processed, quitting..."
            sys.exit(0)

    else:
        print "Duplicate entries for user, check database consistency"
        print "Quitting..."
        sys.exit(0)

    userTest = service[1].people().get(userId='me').execute()


    # 4.75. Set up the query and get all the messages that match
    query_sent = getQuery(NUM_DAYS, 'sent', "")
    response_sent = Message.ListMessagesMatchingQuery(service[0], user, query_sent)

    recipients = Message.extractRecipients(response_sent, user, service[0])

    # print "Recipients", recipients

    # Group recipients into 10s to decrease the number of queries
    accumulatedRecipients = []
    for i in range(0, len(recipients), 10):
        accumulatedRecipients.append(" OR ".join(recipients[i:i+10]))

    # print "Accumulated recipients:", accumulatedRecipients


    emails_to_process = set()
    for recipient_email in accumulatedRecipients:
        query_section = getQuery(NUM_DAYS, 'all', recipient_email)
        response_section = Message.ListMessagesMatchingQuery(service[0], user, query_section)

        for x in response_section:
            emails_to_process.add( (x["id"], x["threadId"]) )


    response_all = [{'id': item[0], 'threadId': item[1]} for item in emails_to_process]

    #query_all = getQuery(NUM_DAYS, 'all', "")
    #response_all = Message.ListMessagesMatchingQuery(service[0], user, query_all)





#.........这里部分代码省略.........
开发者ID:mturek,项目名称:Test92,代码行数:103,代码来源:main.py


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