forked from mozilla/zamboni
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move blog post cron over to django (bug 661443)
- Loading branch information
Showing
4 changed files
with
436 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.conf import settings | ||
|
||
import commonware.log | ||
from dateutil import parser | ||
import feedparser | ||
|
||
import cronjobs | ||
from devhub.models import BlogPost | ||
|
||
log = commonware.log.getLogger('z.cron') | ||
|
||
|
||
@cronjobs.register | ||
def update_blog_posts(): | ||
"""Update the blog post cache.""" | ||
|
||
items = feedparser.parse(settings.DEVELOPER_BLOG_URL)['items'] | ||
if not items: | ||
return | ||
|
||
BlogPost.objects.all().delete() | ||
|
||
for item in items[:5]: | ||
post = {} | ||
post['title'] = item.title | ||
post['date_posted'] = parser.parse(item.date) | ||
post['permalink'] = item.link | ||
BlogPost.objects.create(**post) | ||
|
||
log.info('Adding %d blog posts.' % BlogPost.objects.count()) | ||
|
Oops, something went wrong.