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)