diff --git a/apps/notification/management/commands/animail_logs.py b/apps/notification/management/commands/animail_logs.py index 57bac50f..a783dbaf 100644 --- a/apps/notification/management/commands/animail_logs.py +++ b/apps/notification/management/commands/animail_logs.py @@ -1,6 +1,6 @@ from email.utils import format_datetime import requests -from datetime import datetime +from datetime import datetime, timedelta from django.core.management.base import BaseCommand from django.conf import settings @@ -45,7 +45,13 @@ class Command(BaseCommand): parser.add_argument( '--date', dest='date', - help='Date', + help='Date in format 22-1-2019', + ) + parser.add_argument( + '--days', + type=int, + dest='days', + help='Days after date', ) parser.add_argument( '--subject', @@ -55,11 +61,14 @@ class Command(BaseCommand): def handle(self, *args, **options): emails = [] - end_dt = datetime(2019, 7, 11) - current_dt = options.get('date') + current_dt = datetime.strptime(options.get('date'), '%d-%m-%Y') + end_dt = current_dt + timedelta(options.get('days') or 1) while current_dt <= end_dt: - e, current_dt = get_logs(options.get('limit'), current_dt, options.get('subject')) + e, dt = get_logs(options.get('limit') or 300, current_dt, options.get('subject')) emails += e + if current_dt == dt: + break + current_dt = dt print(set(emails)) print(current_dt)