Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Creating a weekly digest

Say our blog has a lot of people who don't use RSS, and prefer mailing lists. 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 blog/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(7 - date.weekday())    else:        date = date - datetime.timedelta(date.weekday()) delta ...
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

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content