Beispiel #1
0
    def update_subscriptions(self, user, device, add, remove):

        conflicts = intersect(add, remove)
        if conflicts:
            msg = "can not add and remove '{}' at the same time".format(str(conflicts))
            logger.warning(msg)
            raise RequestException(msg)

        add_s = list(map(normalize_feed_url, add))
        rem_s = list(map(normalize_feed_url, remove))

        assert len(add) == len(add_s) and len(remove) == len(rem_s)

        pairs = zip(add + remove, add_s + rem_s)
        updated_urls = list(filter(lambda pair: pair[0] != pair[1], pairs))

        add_s = filter(None, add_s)
        rem_s = filter(None, rem_s)

        # If two different URLs (in add and remove) have
        # been sanitized to the same, we ignore the removal
        rem_s = filter(lambda x: x not in add_s, rem_s)

        for add_url in add_s:
            podcast = Podcast.objects.get_or_create_for_url(add_url).object
            subscribe(podcast.pk, user.pk, device.uid, add_url)

        remove_podcasts = Podcast.objects.filter(urls__url__in=rem_s)
        for podcast in remove_podcasts:
            unsubscribe(podcast.pk, user.pk, device.uid)

        return updated_urls
Beispiel #2
0
    def update_subscriptions(self, user, device, add, remove):

        conflicts = intersect(add, remove)
        if conflicts:
            msg = "can not add and remove '{}' at the same time".format(
                str(conflicts))
            logger.warn(msg)
            raise RequestException(msg)

        add_s = list(map(normalize_feed_url, add))
        rem_s = list(map(normalize_feed_url, remove))

        assert len(add) == len(add_s) and len(remove) == len(rem_s)

        pairs = zip(add + remove, add_s + rem_s)
        updated_urls = list(filter(lambda pair: pair[0] != pair[1], pairs))

        add_s = filter(None, add_s)
        rem_s = filter(None, rem_s)

        # If two different URLs (in add and remove) have
        # been sanitized to the same, we ignore the removal
        rem_s = filter(lambda x: x not in add_s, rem_s)

        for add_url in add_s:
            podcast = Podcast.objects.get_or_create_for_url(add_url)
            subscribe(podcast, user, device, add_url)

        remove_podcasts = Podcast.objects.filter(urls__url__in=rem_s)
        for podcast in remove_podcasts:
            unsubscribe(podcast, user, device)

        return updated_urls
Beispiel #3
0
    def update_subscriptions(self, user, device, add, remove):

        conflicts = intersect(add, remove)
        if conflicts:
            msg = "can not add and remove '{}' at the same time".format(
                str(conflicts))
            raise RequestException(msg)

        add_s = map(normalize_feed_url, add)
        rem_s = map(normalize_feed_url, remove)

        assert len(add) == len(add_s) and len(remove) == len(rem_s)

        pairs = zip(add + remove, add_s + rem_s)
        updated_urls = filter(lambda (a, b): a != b, pairs)

        add_s = filter(None, add_s)
        rem_s = filter(None, rem_s)

        # If two different URLs (in add and remove) have
        # been sanitized to the same, we ignore the removal
        rem_s = filter(lambda x: x not in add_s, rem_s)

        subscriber = BulkSubscribe(user, device)

        for a in add_s:
            subscriber.add_action(a, 'subscribe')

        for r in rem_s:
            subscriber.add_action(r, 'unsubscribe')

        try:
            subscriber.execute()
        except BulkException as be:
            for err in be.errors:
                msg = 'Advanced API: {user}: Updating subscription for ' \
                      '{podcast} on {device} failed: {err} {reason}'.format(
                          user=user.username, podcast=err.doc,
                          device=device.uid, err=err.error, reason=err.reason)
                loger.error(msg)

        return updated_urls
Beispiel #4
0
def similar_urls(a, b):
    """ Two Podcasts/Episodes are merged, if they have the same URLs"""
    return bool(utils.intersect(a.urls, b.urls))