From 257c603986d0ef18ac2c6896c733dcea1d699c45 Mon Sep 17 00:00:00 2001 From: hyfc <3365132+hyfc@users.noreply.github.com> Date: Mon, 11 Jun 2018 00:10:50 +0800 Subject: parse date with different format --- utils/mail.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'utils') diff --git a/utils/mail.py b/utils/mail.py index f26e7b8..c1cd3d8 100644 --- a/utils/mail.py +++ b/utils/mail.py @@ -70,10 +70,13 @@ def get_mail_details(msg): except IndexError: maildetails.subject = subject received_time = msg.get("Date") - time_str_fmt = "%a, %d %b %Y %H:%M:%S %z" - time_obj = datetime.strptime(received_time, time_str_fmt) - time_obj = time_obj.astimezone(pytz.timezone('Asia/Hong_Kong')) - maildetails.receivedtime = time_obj.strftime(time_str_fmt) + if received_time.endswith('(CST)'): + maildetails.receivedtime = received_time + else: + time_str_fmt = "%a, %d %b %Y %H:%M:%S %z" + time_obj = datetime.strptime(received_time, time_str_fmt) + time_obj = time_obj.astimezone(pytz.timezone('Asia/Hong_Kong')) + maildetails.receivedtime = time_obj.strftime(time_str_fmt) parts = msg.get_payload() content_charset = parts[0].get_content_charset() -- cgit v1.2.3