Compare commits
No commits in common. "e59c9d2f4154ea4e0ac0c53dff144d10d800079a" and "55202ba3b0607ef13017253df4e602b4b1263bc7" have entirely different histories.
e59c9d2f41
...
55202ba3b0
3 changed files with 8 additions and 23 deletions
|
@ -58,19 +58,11 @@ class Item(models.Model):
|
|||
})
|
||||
return json.dumps(comments)
|
||||
|
||||
@classmethod
|
||||
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)
|
||||
qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published')
|
||||
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)
|
||||
|
@ -85,7 +77,11 @@ class Item(models.Model):
|
|||
else:
|
||||
last_monday = monday - timedelta(days=7)
|
||||
week = qs.filter(published__gt=last_monday)
|
||||
archive = qs.exclude(id__in=week)
|
||||
archive = (qs
|
||||
.exclude(id__in=week)
|
||||
.annotate(year=ExtractYear('published'))
|
||||
.annotate(week=ExtractWeek('published'))
|
||||
)
|
||||
return week, archive
|
||||
|
||||
def get_week(self):
|
||||
|
|
|
@ -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.all_public()
|
||||
_, archive = models.Item.public()
|
||||
if year and month and day:
|
||||
date = datetime.strptime('%s-%s-%s' % (year, month, day), '%Y-%m-%d')
|
||||
week = int(date.strftime('%W'))
|
||||
|
|
|
@ -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).json()
|
||||
r = requests.get(url + '?per_page=10000', auth=auth)
|
||||
ids = [sub['subscriber_id'] for sub in r['data']['results']]
|
||||
url = settings.LISTMONK_API + 'subscribers'
|
||||
for id in ids:
|
||||
|
@ -90,14 +90,3 @@ 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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue