You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
from django.core.management.base import BaseCommand
|
|
from django.conf import settings
|
|
import json
|
|
import requests
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Get animail logs'
|
|
|
|
def add_arguments(self, parser):
|
|
# Named (optional) arguments
|
|
parser.add_argument(
|
|
'--limit',
|
|
type=int,
|
|
dest='limit',
|
|
help='Limit',
|
|
)
|
|
parser.add_argument(
|
|
'--date',
|
|
dest='date',
|
|
help='Date',
|
|
)
|
|
parser.add_argument(
|
|
'--subject',
|
|
dest='subject',
|
|
help='Subject',
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
r = requests.get(
|
|
"https://api.mailgun.net/v3/%s/events" % settings.ANYMAIL['MAILGUN_SENDER_DOMAIN'],
|
|
auth=("api", settings.ANYMAIL['MAILGUN_API_KEY']),
|
|
params={"begin": options.get('date'),
|
|
"ascending": "yes",
|
|
"limit": options.get('limit'),
|
|
"pretty": "yes", })
|
|
print(r)
|
|
messages = json.loads(r.content)
|
|
print("len(messages['items'])", len(messages['items']))
|
|
no_attach = list(filter(lambda i: i['message']['headers']['subject'] == options.get('subject') and not len(
|
|
i['message']['attachments']), messages['items']))
|
|
print("len(no_attach)", len(no_attach))
|
|
print([m['message']['headers']['to'] for m in no_attach])
|
|
|
|
|