Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #54 from brutasse/fix/update-django-push

Updated django-push to 0.5
  • Loading branch information...
commit 3d592f71be0f6297958695ee551a4f8768c3fa76 2 parents 94afeeb + 40750ec
@aaugustin aaugustin authored
View
42 aggregator/management/commands/update_subscriptions.py
@@ -0,0 +1,42 @@
+import logging
+
+from datetime import timedelta
+
+from django.conf import settings
+from django.core.management.base import NoArgsCommand
+from django.utils import timezone
+from django_push.subscriber.models import Subscription
+
+from ...models import Feed, APPROVED_FEED
+
+
+logger = logging.getLogger(__name__)
+
+
+class Command(NoArgsCommand):
+ def handle_noargs(self, **kwargs):
+ feed_urls = set(Feed.objects.filter(
+ is_defunct=False, approval_status=APPROVED_FEED
+ ).values_list('feed_url', flat=True))
+
+ subscribed_urls = set(Subscription.objects.values_list('topic',
+ flat=True))
+
+ missing_feeds = feed_urls - subscribed_urls
+ extra_feeds = subscribed_urls - feed_urls
+
+ for url in missing_feeds:
+ logger.info(u'Subscribing to {0}'.format(url))
+ Subscription.objects.subscribe(url, settings.PUSH_HUB)
+
+ for subscription in Subscription.objects.filter(topic__in=extra_feeds):
+ logger.info(u'Unsubscribing from {0} ({1})'.format(
+ subscription.pk, subscription.topic))
+ subscription.unsubscribe()
+
+ limit = timezone.now() + timedelta(days=2)
+ for subscription in Subscription.objects.exclude(
+ topic__in=extra_feeds).filter(lease_expiration__lte=limit):
+ logger.info(u'Renewing subscription for {0} ({1})'.format(
+ subscription.topic, subscription.pk))
+ subscription.subscribe()
View
16 aggregator/models.py
@@ -1,14 +1,15 @@
import logging
import datetime
+import feedparser
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django_push.subscriber import signals as push_signals
from django_push.subscriber.models import Subscription
-from django.conf import settings
log = logging.getLogger(__name__)
+
class FeedType(models.Model):
name = models.CharField(max_length=250)
slug = models.SlugField(max_length=250)
@@ -50,8 +51,8 @@ def save(self, **kwargs):
def delete(self, **kwargs):
super(Feed, self).delete(**kwargs)
- if settings.SUPERFEEDR_CREDS != None:
- Subscription.objects.unsubscribe(self.feed_url, settings.PUSH_HUB)
+ if settings.SUPERFEEDR_CREDS is not None:
+ Subscription.objects.get(topic=self.feed_url).unsubscribe()
class FeedItemManager(models.Manager):
def create_or_update_by_guid(self, guid, **kwargs):
@@ -108,14 +109,19 @@ def __unicode__(self):
def get_absolute_url(self):
return self.link
+
def feed_updated(sender, notification, **kwargs):
- log.debug('Recieved notification on subscription ID %s (%s)', sender.id, sender.topic)
+ log.debug('Recieved notification on subscription ID %s (%s)',
+ sender.id, sender.topic)
try:
feed = Feed.objects.get(feed_url=sender.topic)
except Feed.DoesNotExist:
- log.error("Subscription ID %s (%s) doesn't have a feed.", sender.id, sender.topic)
+ log.error("Subscription ID %s (%s) doesn't have a feed.",
+ sender.id, sender.topic)
return
+ notification = feedparser.parse(notification)
+
for entry in notification.entries:
title = entry.title
try:
View
3  deploy-requirements.txt
@@ -4,7 +4,7 @@ akismet == 0.2.0
Django == 1.5.4
django-contact-form == 1.0
django-haystack == 1.2.7
-django-push == 0.4
+django-push == 0.6
django-registration==1.0
django-secure == 1.0
docutils == 0.10
@@ -13,6 +13,7 @@ Jinja2 == 2.6
psycopg2 == 2.5
python-memcached == 1.48
raven == 1.4.6
+requests == 1.2.3
South == 0.7.6
Sphinx == 1.2b3
Unipath == 1.0
Please sign in to comment.
Something went wrong with that request. Please try again.