Compare commits

..

2 commits

Author SHA1 Message Date
j
e59c9d2f41 current week 2023-10-01 09:08:09 +02:00
j
502f6fb2b9 list management 2023-10-01 09:07:48 +02:00
3 changed files with 23 additions and 8 deletions

View file

@ -59,10 +59,18 @@ class Item(models.Model):
return json.dumps(comments) return json.dumps(comments)
@classmethod @classmethod
def public(cls, now=None): def all_public(cls, now=None):
if now is None: if now is None:
now = timezone.make_aware(datetime.now(), timezone.get_default_timezone()) now = timezone.make_aware(datetime.now(), timezone.get_default_timezone())
qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published') 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() cal = now.date().isocalendar()
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1) monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo) monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo)
@ -77,11 +85,7 @@ class Item(models.Model):
else: else:
last_monday = monday - timedelta(days=7) last_monday = monday - timedelta(days=7)
week = qs.filter(published__gt=last_monday) week = qs.filter(published__gt=last_monday)
archive = (qs archive = qs.exclude(id__in=week)
.exclude(id__in=week)
.annotate(year=ExtractYear('published'))
.annotate(week=ExtractWeek('published'))
)
return week, archive return week, archive
def get_week(self): def get_week(self):

View file

@ -77,7 +77,7 @@ def index(request):
def archive(request, year=None, month=None, day=None, week=None): def archive(request, year=None, month=None, day=None, week=None):
context = default_context(request) context = default_context(request)
_, archive = models.Item.public() archive = models.Item.all_public()
if year and month and day: if year and month and day:
date = datetime.strptime('%s-%s-%s' % (year, month, day), '%Y-%m-%d') date = datetime.strptime('%s-%s-%s' % (year, month, day), '%Y-%m-%d')
week = int(date.strftime('%W')) week = int(date.strftime('%W'))

View file

@ -81,7 +81,7 @@ def add_email(email):
def delete_bounced_emails(): def delete_bounced_emails():
url = settings.LISTMONK_API + 'bounces' url = settings.LISTMONK_API + 'bounces'
auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD) 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']] ids = [sub['subscriber_id'] for sub in r['data']['results']]
url = settings.LISTMONK_API + 'subscribers' url = settings.LISTMONK_API + 'subscribers'
for id in ids: for id in ids:
@ -90,3 +90,14 @@ def delete_bounced_emails():
print(id) 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)