NewsBlur/apps/rss_feeds/views.py

27 lines
1,002 B
Python
Raw Normal View History

from django.shortcuts import get_object_or_404
2010-07-26 14:37:17 -04:00
from apps.rss_feeds.models import Feed
from utils import json
@json.json_view
def load_feed_statistics(request):
stats = dict()
feed_id = request.GET['feed_id']
feed = get_object_or_404(Feed, pk=feed_id)
# Dates of last and next update
stats['last_update'] = feed.last_update
stats['next_update'] = feed.next_scheduled_update
# Minutes between updates
update_interval_minutes, random_factor = feed.get_next_scheduled_update()
stats['update_interval_minutes'] = update_interval_minutes
# Stories per month - average and month-by-month breakout
2010-07-26 14:37:17 -04:00
average_stories_per_month, stories_last_year = feed.average_stories_per_month, feed.stories_last_year
stats['average_stories_per_month'] = average_stories_per_month
stats['stories_last_year'] = stories_last_year and json.decode(stories_last_year)
# Subscribers
stats['subscriber_count'] = feed.num_subscribers
return stats