'How to make a time restriction in outlook using python?

I am making a program that:

  • opens outlook
  • find emails per subject
  • extract some date from emails (code and number)
  • fills these data in excel file in.

Standard email looks like this:

Subject: Test1

 Hi,
 You got a new answer from user Alex. 

 Code: alex123fj
 Number1: 0611111111
 Number2: 1020
 Number3: 3032

I encounter 2 main problems in the process. Firstly, I do not get how to make time restriction for emails in outlook. For example, if I want to read emails only from yesterday. Secondly, all codes and numbers from email I save in lists. But every item gets this ["alex123fj/r"] in place from this ["alex123fj"]

I would appreciate any help or advice, that is my first ever program in Python.

Here is my code:

import win32com.client
import re

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.Folders('myemail@....').Folders('Inbox')

messages = inbox.Items

def get_code(messages):
     codes_lijst = []
     for message in messages:
        subject = message.subject
        if subject == "Test1":
           body = message.body
           matches = re.finditer("Code:\s(.*)$", body, re.MULTILINE)
           for match in matches:
            codes_lijst.append(match.group(1))
        return codes_lijst


def  get_number(messages):
numbers_lijst = []
for message in messages:
    subject = message.subject
    if subject == "Test1":
        body = message.body
        matches = re.finditer("Number:\s(.*)$", body, re.MULTILINE)
        for match in matches:
            numbers_lijst.append(match.group(1))
return numbers_lijst


code = get_code(messages)
number = get_number(messages)

print(code)
print(number)


Solution 1:[1]

You will have records left in memory being processed if the application or processing logic doesn't stop with the consumer thread.

If offsets were committed beforehand, those records would effectively be skipped after a rebalance. Otherwise, those offsets ideally shouldn't be committed post-processing since those records might be tried to be processed again, potentially resulting in data duplication, by other consumers after a rebalance.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 OneCricketeer