Esempio n. 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