コード例 #1
0
    def get_orders(self, mail, email_id):
        if email_id not in self.email_to_orders:
            for attempt in range(3):
                try:
                    _, data = mail.uid("FETCH", email_id, "(RFC822)")
                    break
                except:
                    tqdm.write(
                        f"Got exception, attempting retry up to 3 times...\n{util.get_traceback_lines()}"
                    )
                    mail = email_auth.email_authentication()
                    mail.select('"[Gmail]/All Mail"')
            else:
                raise Exception("Exceeded retry limit")

            msg = email.message_from_string(str(data[0][1], 'utf-8'))
            date = datetime.datetime.strptime(
                msg['Date'], '%a, %d %b %Y %H:%M:%S %z').strftime('%Y-%m-%d')
            to_email = str(msg['To']).replace('<', '').replace('>', '')
            raw_email = str(data[0][1]).replace("=3D", "=").replace(
                '=\\r\\n', '').replace('\\r\\n', '').replace('&amp;', '&')
            order_ids = AmazonTrackingRetriever.get_order_ids_from_email(
                AmazonTrackingRetriever, raw_email)
            self.email_to_orders[email_id] = [
                Order(order_id, date, to_email, False)
                for order_id in order_ids
            ]
            self.flush()
        return self.email_to_orders[email_id]
コード例 #2
0
def get_order_ids_to_orders(args):
  mail = email_auth.email_authentication()
  mail.select('"[Gmail]/All Mail"')
  email_ids = get_email_ids(mail, args)

  config = open_config()
  email_to_orders = EmailToOrders(config)
  result = {}
  for email_id in tqdm(email_ids, desc="Fetching orders", unit="email"):
    for order in email_to_orders.get_orders(mail, email_id):
      result[order.order_id] = order

  return result
コード例 #3
0
 def load_mail(self):
   mail = email_auth.email_authentication()
   mail.select('"[Google Mail]/All Mail"')
   return mail
コード例 #4
0
 def _get_all_mail_folder(self) -> IMAP4_SSL:
     mail = email_auth.email_authentication()
     mail.select('"[Gmail]/All Mail"')
     return mail
コード例 #5
0
 def get_all_mail_folder(self) -> imaplib.IMAP4_SSL:
     mail = email_auth.email_authentication()
     mail.select('"[Google Mail]/All Mail"')
     return mail