switch feed_emails command to python 3

This commit is contained in:
Frédéric Péters 2019-11-01 14:05:52 +01:00
parent c2ad39e4bd
commit cd74feb4a1
1 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import datetime
import email.utils
import mailbox
import rfc822
import time
from django.core.management.base import BaseCommand
@ -21,11 +21,14 @@ class Command(BaseCommand):
message = box[message_id]
try:
list_id = message['list-id'].strip('<>').replace('.listes.entrouvert.com', '')
except KeyError:
print 'failed to get list id', message['date'], message['subject']
except (KeyError, AttributeError):
print('failed to get list id', message['date'], message['subject'])
continue
author_email = rfc822.parseaddr(message['From'])[1]
author_date = datetime.datetime.fromtimestamp(time.mktime(rfc822.parsedate(message['date'])))
try:
author_email = email.utils.parseaddr(message['From'])[1]
except TypeError:
continue
author_date = email.utils.parsedate_to_datetime(message['date'])
msg, created = Email.objects.get_or_create(msgid=message_id,
defaults={