Skip to Content
Mastering Flask
book

Mastering Flask

by Jack Stouffer
September 2015
Intermediate to advanced
288 pages
5h 30m
English
Packt Publishing
Content preview from Mastering Flask

Creating a weekly digest

Say our blog has a lot of people who don't use RSS and prefer mailing lists, which is a large number of users. We need some way to create a list of new posts at the end of every week to increase our site's traffic. To solve this problem, we will create a digest task that will be called by a beat worker at 10 am every Saturday.

First, in tasks.py, let's create our task as follows:

@celery.task( bind=True, ignore_result=True, default_retry_delay=300, max_retries=5 ) def digest(self): # find the start and end of this week year, week = datetime.datetime.now().isocalendar()[0:2] date = datetime.date(year, 1, 1) if (date.weekday() > 3): date = date + datetime.timedelta(days=7 - date.weekday()) else: date = date - datetime.timedelta(days=date.weekday()) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

An Introduction to Flask

An Introduction to Flask

Miguel Grinberg
Flask Blueprints

Flask Blueprints

Joel Perras
Flask By Example

Flask By Example

Gareth Dwyer

Publisher Resources

ISBN: 9781784393656Supplemental Content