diff options
| author | hyfc <3365132+hyfc@users.noreply.github.com> | 2018-06-11 00:10:50 +0800 | 
|---|---|---|
| committer | hyfc <3365132+hyfc@users.noreply.github.com> | 2020-10-22 11:37:38 +0800 | 
| commit | 257c603986d0ef18ac2c6896c733dcea1d699c45 (patch) | |
| tree | 5d8c6de19ee4843ac1cf5e89fd26541cabc31279 /utils | |
| parent | 9d71b348da48ac3c9c5da2e36c8741a7bd38ef1a (diff) | |
| download | telegram-mail-bot-257c603986d0ef18ac2c6896c733dcea1d699c45.tar.gz telegram-mail-bot-257c603986d0ef18ac2c6896c733dcea1d699c45.tar.bz2 telegram-mail-bot-257c603986d0ef18ac2c6896c733dcea1d699c45.zip | |
parse date with different format
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/mail.py | 11 | 
1 files changed, 7 insertions, 4 deletions
| 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() | 
