parent
bd55fca451
commit
aa27c1b0db
2 changed files with 48 additions and 4 deletions
@ -0,0 +1,43 @@ |
|||||||
|
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]) |
||||||
|
|
||||||
Loading…
Reference in new issue