From b4b4ae18b48f6b42c0df4fb26237e43f12a69d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Emre=20G=C3=BCndo=C4=9Fmu=C5=9F?= <32923721+yemregundogmus@users.noreply.github.com> Date: Sun, 17 Dec 2023 01:26:51 +0300 Subject: [PATCH] bugfix on utc error --- twscrape/imap.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/twscrape/imap.py b/twscrape/imap.py index e591a5b..9f934ef 100644 --- a/twscrape/imap.py +++ b/twscrape/imap.py @@ -46,8 +46,10 @@ def _wait_email_code(imap: imaplib.IMAP4_SSL, count: int, min_t: datetime | None for x in rep: if isinstance(x, tuple): msg = emaillib.message_from_bytes(x[1]) - - msg_time = datetime.strptime(msg.get("Date", ""), "%a, %d %b %Y %H:%M:%S %z") + try: + msg_time = datetime.strptime(msg.get("Date", "").split(' (')[0], "%a, %d %b %Y %H:%M:%S %z") + except ValueError: + msg_time = msg.get("Date", "") msg_from = str(msg.get("From", "")).lower() msg_subj = str(msg.get("Subject", "")).lower() logger.info(f"({i} of {count}) {msg_from} - {msg_time} - {msg_subj}")