當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。