Ejemplo n.º 1
0
 def setUp(self):
     self.subscription = Subscription(
         hub="http://testhub.example.com", topic="http://example.com/foo", verified=True, verify_token="blah"
     )
     self.subscription.save()
     self.signals = []
     updated.connect(self.signal_handler)
Ejemplo n.º 2
0
 def setUp(self):
     self.subscription = Subscription.objects.create(
         hub='http://testhub.example.com',
         topic='http://example.com/foo',
         verified=True,
         verify_token='blah')
     self.signals = []
     updated.connect(self.signal_handler)
Ejemplo n.º 3
0
                url = link['href']
                break

    if url is None:
        return

    entries = list(
        filter(None, [
            UniqueFeedManager.entry_data(entry, notification)
            for entry in notification.entries
        ]))
    if len(entries):
        enqueue(store_entries, args=[url, entries], queue='store')


updated.connect(pubsubhubbub_update)


class FaviconManager(models.Manager):
    def update_favicon(self, url, force_update=False):
        if not url:
            return
        parsed = list(urlparse.urlparse(url))
        if not parsed[0].startswith('http'):
            return
        favicon, created = self.get_or_create(url=url)
        feeds = Feed.objects.filter(url=url, favicon='')
        if (not created and not force_update) and favicon.favicon:
            # Still, add to existing
            favicon_urls = list(
                self.filter(url=url).exclude(favicon='').values_list(
Ejemplo n.º 4
0
        for link in notification.feed.get('links', []):
            if link['rel'] == 'self':
                url = link['href']
                break

    if url is None:
        return

    entries = list(filter(
        None,
        [UniqueFeedManager.entry_data(
            entry, notification) for entry in notification.entries]
    ))
    if len(entries):
        enqueue(store_entries, args=[url, entries], queue='store')
updated.connect(pubsubhubbub_update)


class FaviconManager(models.Manager):
    def update_favicon(self, url, force_update=False):
        if not url:
            return
        parsed = list(urlparse.urlparse(url))
        if not parsed[0].startswith('http'):
            return
        favicon, created = self.get_or_create(url=url)
        feeds = Feed.objects.filter(url=url, favicon='')
        if (not created and not force_update) and favicon.favicon:
            # Still, add to existing
            favicon_urls = list(self.filter(url=url).exclude(
                favicon='').values_list('favicon', flat=True))
Ejemplo n.º 5
0
def link_delete_handler(sender, **kwargs):
    """If the link had an associated feed subscription, unsubscribe."""
    link = kwargs.get('instance', None)

    if not isinstance(link, Link):
        return

    if not link.subscription:
        return

    tasks.UnsubscribeFromFeed.apply_async(args=(link,))
post_delete.connect(link_delete_handler, sender=Link)


def listener(notification, **kwargs):
    """
    Create activity entries when we receive notifications of
    feed updates from a hub.
    """
    sender = kwargs.get('sender', None)
    if not sender:
        return
    try:
        log.debug('Received feed update notification: %s, sender: %s' % (notification, sender))
        eager_result = tasks.HandleNotification.apply_async(args=(notification, sender))
        log.debug('Result from the feed notification handler: %s, %s' % (eager_result.status, eager_result.result))
    except Exception, ex:
        log.warn("Unprocessable notification: %s (%s)" % (notification, ex))
updated.connect(listener)
Ejemplo n.º 6
0
 def setUp(self):
     self.signals = []
     updated.connect(self._signal_handler)
Ejemplo n.º 7
0
 def setUp(self):
     self.subscription = Subscription.objects.create(
         hub='http://testhub.example.com', topic='http://example.com/foo',
         verified=True, verify_token='blah')
     self.signals = []
     updated.connect(self.signal_handler)
Ejemplo n.º 8
0
post_save.connect(link_create_handler, sender=Link)


def link_delete_handler(sender, **kwargs):
    """If the link had an associated feed subscription, unsubscribe."""
    link = kwargs.get('instance', None)

    if not isinstance(link, Link):
        return

    if not link.subscription:
        return

    tasks.UnsubscribeFromFeed.apply_async(args=(link,))
post_delete.connect(link_delete_handler, sender=Link)


def listener(notification, **kwargs):
    """
    Create activity entries when we receive notifications of
    feed updates from a hub.
    """
    sender = kwargs.get('sender', None)
    if not sender:
        return
    try:
        tasks.HandleNotification.apply_async(args=(notification, sender))
    except:
        log.warn("Unprocessable notification: %s" % (notification,))
updated.connect(listener)
Ejemplo n.º 9
0
    #               <day>Saturday</day>
    #               <day>Sunday</day>
    #             </skipDays>
    # skipHours:  <skipHours>
    #               <hour>0</hour>
    #             </skipHours>
    # textInput:  <textinput>
    #               <description>Search Google</description>
    #               <title>Search</title>
    #               <link>http://www.google.no/search?</link>
    #               <name>q</name>
    #             </textinput>
    # ttl: <ttl>60</ttl>
    # webMaster: <webMaster>[email protected]</webMaster>

updated.connect(Feed.pubsubhubbub_listener)

class FeedItemManager(models.Manager):
    '''A manager for user-specific queries.'''

    def for_user(self, user):
        userfeeditems = UserFeedItem.objects.filter(user=user)
        items = self.filter(userfeeditems__in=userfeeditems)
        return items


class FeedItem(models.Model):
    '''A model for representing an item in a RSS feed.'''

    objects = FeedItemManager()
Ejemplo n.º 10
0
    def __unicode__(self):
        return u'%s -> %s' % (self.name, self.url)


def link_subscriber(sender, instance, created, **kwargs):
    """Subscribe to link RSS/Atom feed."""
    if not isinstance(instance, Link) or not instance.subscribe:
        return
    if instance.subscription:
        return
    tasks.PushSubscriber.apply_async(args=(instance,))
post_save.connect(link_subscriber, sender=Link)


def link_delete_handler(sender, instance, **kwargs):
    """Send unsubscribe request to link hub."""
    if not isinstance(instance, Link):
        return
    tasks.PushUnsubscriber.apply_async(args=(instance,))
pre_delete.connect(link_delete_handler, sender=Link)


def notification_listener(notification, **kwargs):
    """Create entries for notification."""
    sender = kwargs.get('sender', None)
    if not sender:
        return
    tasks.PushNotificationHandler.apply_async(args=(notification, sender))
updated.connect(notification_listener)
Ejemplo n.º 11
0
        return

    tasks.UnsubscribeFromFeed.apply_async(args=(link, ))


post_delete.connect(link_delete_handler,
                    sender=Link,
                    dispatch_uid='links_link_delete_handler')


def listener(notification, **kwargs):
    """
    Create activity entries when we receive notifications of
    feed updates from a hub.
    """
    sender = kwargs.get('sender', None)
    if not sender:
        return
    try:
        msg = 'Received feed update notification: %s, sender: %s'
        log.debug(msg % (notification, sender))
        eager_result = tasks.HandleNotification.apply_async(args=(notification,
                                                                  sender))
        msg = 'Result from the feed notification handler: %s, %s'
        log.debug(msg % (eager_result.status, eager_result.result))
    except Exception, ex:
        log.warn("Unprocessable notification: %s (%s)" % (notification, ex))


updated.connect(listener, dispatch_uid='links_listener')
    """Subscribe to link RSS/Atom feed."""
    if not isinstance(instance, Link) or not instance.subscribe:
        return
    if instance.subscription:
        return
    tasks.PushSubscriber.apply_async(args=(instance, ))


post_save.connect(link_subscriber, sender=Link)


def link_delete_handler(sender, instance, **kwargs):
    """Send unsubscribe request to link hub."""
    if not isinstance(instance, Link):
        return
    tasks.PushUnsubscriber.apply_async(args=(instance, ))


pre_delete.connect(link_delete_handler, sender=Link)


def notification_listener(notification, **kwargs):
    """Create entries for notification."""
    sender = kwargs.get('sender', None)
    if not sender:
        return
    tasks.PushNotificationHandler.apply_async(args=(notification, sender))


updated.connect(notification_listener)