From aa27c1b0dbdaaffb6c08a921133e21a97c2df49c Mon Sep 17 00:00:00 2001 From: gzbender Date: Thu, 11 Jul 2019 23:36:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=D0=B8=D1=81=D1=8C=20=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BE=D1=82=D1=8B=20=D0=B7=D0=B0=20=D1=80=D0=B8=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BB=D0=B0=D0=B3?= =?UTF-8?q?=D0=B5=D1=80=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/animail_logs.py | 43 +++++++++++++++++++ apps/notification/tasks.py | 9 ++-- 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 apps/notification/management/commands/animail_logs.py diff --git a/apps/notification/management/commands/animail_logs.py b/apps/notification/management/commands/animail_logs.py new file mode 100644 index 00000000..c1df0c42 --- /dev/null +++ b/apps/notification/management/commands/animail_logs.py @@ -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]) + diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py index f1748700..791ed307 100644 --- a/apps/notification/tasks.py +++ b/apps/notification/tasks.py @@ -190,18 +190,19 @@ def send_camp_certificates(email=None, dry_run=False, certificate_number=None): color = (24, 57, 220) if email: fn = draw_cert(os.path.join(settings.RESOURCES_ROOT, signed_path_pattern % certificate_number), email, 'Имя', 'Фамилия', - font_size=120, y=1000, color=color) + font_size=120, y=1000, color=color) file = open(fn, 'rb') try: send_email('Грамота от Lil School', email, 'notification/email/camp_certificate.html', attachments=[(file.name, file.read(), 'image/jpeg')], certificate_number=certificate_number) - except: - pass + # send_email('Грамота от Lil School', email, 'notification/email/camp_certificate.html', + # attachments=[('file', '', 'image/jpeg')], certificate_number=certificate_number) + except Exception as e: + print(e) else: print('Email has been sent') finally: file.close() - os.remove(fn) return date_end = date(now().year, 6 + certificate_number, 1) - timedelta(1)