diff --git a/app/item/models.py b/app/item/models.py index 1d7baec..ef325eb 100644 --- a/app/item/models.py +++ b/app/item/models.py @@ -59,10 +59,18 @@ class Item(models.Model): return json.dumps(comments) @classmethod - def public(cls, now=None): + def all_public(cls, now=None): if now is None: now = timezone.make_aware(datetime.now(), timezone.get_default_timezone()) qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published') + archive = qs.annotate(year=ExtractYear('published')).annotate(week=ExtractWeek('published')) + return archive + + @classmethod + def public(cls, now=None): + if now is None: + now = timezone.make_aware(datetime.now(), timezone.get_default_timezone()) + qs = cls.all_public(now) cal = now.date().isocalendar() monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1) monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo) @@ -77,11 +85,7 @@ class Item(models.Model): else: last_monday = monday - timedelta(days=7) week = qs.filter(published__gt=last_monday) - archive = (qs - .exclude(id__in=week) - .annotate(year=ExtractYear('published')) - .annotate(week=ExtractWeek('published')) - ) + archive = qs.exclude(id__in=week) return week, archive def get_week(self): diff --git a/app/item/views.py b/app/item/views.py index d31247d..d9800d5 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -77,7 +77,7 @@ def index(request): def archive(request, year=None, month=None, day=None, week=None): context = default_context(request) - _, archive = models.Item.public() + archive = models.Item.all_public() if year and month and day: date = datetime.strptime('%s-%s-%s' % (year, month, day), '%Y-%m-%d') week = int(date.strftime('%W')) diff --git a/app/listmonk/utils.py b/app/listmonk/utils.py index 1f1e48e..d6ad2c0 100644 --- a/app/listmonk/utils.py +++ b/app/listmonk/utils.py @@ -81,7 +81,7 @@ def add_email(email): def delete_bounced_emails(): url = settings.LISTMONK_API + 'bounces' auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD) - r = requests.get(url + '?per_page=10000', auth=auth) + r = requests.get(url + '?per_page=10000', auth=auth).json() ids = [sub['subscriber_id'] for sub in r['data']['results']] url = settings.LISTMONK_API + 'subscribers' for id in ids: @@ -90,3 +90,14 @@ def delete_bounced_emails(): print(id) +def delete_blacklisted_emails(): + url = settings.LISTMONK_API + 'subscribers' + auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD) + r = requests.get(url + '?per_page=10000', auth=auth).json() + ids = [u['id'] for u in r['data']['results'] if u['status'] == 'blocklisted'] + for id in ids: + r = requests.delete(url + '?id=%s' % id, auth=auth).json() + if not r.get("data"): + print(id) + +