Пример #1
0
    def _get_bfmr_costs(self) -> TrackingInfoDict:
        mail = self._get_all_mail_folder()
        status, response = mail.uid('SEARCH', None, 'SUBJECT "Payment Sent"',
                                    'SINCE "01-Aug-2019"',
                                    'FROM "*****@*****.**"')
        email_ids = response[0].decode('utf-8').split()
        result: TrackingInfoDict = {}

        for email_id in tqdm(email_ids,
                             desc='Fetching BFMR check-ins',
                             unit='email'):
            email_str = email_tracking_retriever.get_email_content(
                email_id, mail)
            msg = email.message_from_string(email_str)
            date = datetime.datetime.strptime(
                msg['Date'], '%a, %d %b %Y %H:%M:%S %z').strftime(
                    '%Y-%m-%d') if msg['Date'] else ''
            email_str = email_tracking_retriever.clean_email_content(email_str)
            soup = BeautifulSoup(email_str, features="html.parser")

            body = soup.find(id='email_body')
            if not body:
                continue
            tables = body.find_all('table')
            if not tables or len(tables) < 2:
                continue
            table = tables[1]
            fill_busted_bfmr_costs(result, table, date)
            fill_standard_bfmr_costs(result, table, date)
            fill_2020_12_22_bfmr_costs(result, table, date)
        return result
  def _get_bfmr_costs(self):
    mail = self._get_all_mail_folder()
    status, response = mail.uid('SEARCH', None, 'SUBJECT "BuyForMeRetail - Payment Sent"',
                                'SINCE "01-Aug-2019"')
    email_ids = response[0].decode('utf-8').split()
    # some hacks, "po" will just also be the tracking
    tracking_map = dict()
    result = collections.defaultdict(float)

    for email_id in tqdm(email_ids, desc='Fetching BFMR check-ins', unit='email'):
      email_str = email_tracking_retriever.get_email_content(email_id, mail)
      email_str = email_tracking_retriever.clean_email_content(email_str)
      soup = BeautifulSoup(email_str, features="html.parser")

      body = soup.find('td', id='email_body')
      if not body:
        continue
      tables = body.find_all('table')
      if not tables or len(tables) < 2:
        continue
      table = tables[1]
      fill_busted_bfmr_costs(result, tracking_map, table)
      fill_standard_bfmr_costs(result, tracking_map, table)

    return tracking_map, result
Пример #3
0
  def get_relevant_raw_email_data(self, order_id: str, from_email: str) -> Tuple[Optional[str], Optional[str]]:
    status, search_result = self.mail.uid('SEARCH', None, f'BODY "{order_id}"',
                                          f'FROM "{from_email}"')
    email_id = search_result[0]
    if not email_id:
      return None, None

    email_ids = search_result[0].decode('utf-8').split()
    if not email_ids:
      return None, None

    email_str = email_tracking_retriever.get_email_content(email_ids[0], self.mail)
    email_str = email_str.replace('\r\n', '')
    return email_ids[0], email_str