Exemplo n.º 1
0
    def check_feed_address_for_feed_link(self):
        feed_address = None

        if not feedfinder.isFeed(self.feed_address):
            feed_address = feedfinder.feed(self.feed_address)
            if not feed_address:
                feed_address = feedfinder.feed(self.feed_link)
        else:
            feed_address_from_link = feedfinder.feed(self.feed_link)
            if feed_address_from_link != self.feed_address:
                feed_address = feed_address_from_link

        if feed_address:
            try:
                self.feed_address = feed_address
                self.next_scheduled_update = datetime.datetime.utcnow()
                self.has_feed_exception = False
                self.active = True
                self.save()
            except IntegrityError:
                original_feed = Feed.objects.get(feed_address=feed_address)
                original_feed.has_feed_exception = False
                original_feed.active = True
                original_feed.save()
                merge_feeds(original_feed.pk, self.pk)

        return not not feed_address
Exemplo n.º 2
0
    def check_feed_address_for_feed_link(self):
        feed_address = None

        if not feedfinder.isFeed(self.feed_address):
            feed_address = feedfinder.feed(self.feed_address)
            if not feed_address:
                feed_address = feedfinder.feed(self.feed_link)
        else:
            feed_address_from_link = feedfinder.feed(self.feed_link)
            if feed_address_from_link != self.feed_address:
                feed_address = feed_address_from_link

        if feed_address:
            try:
                self.feed_address = feed_address
                self.next_scheduled_update = datetime.datetime.utcnow()
                self.has_feed_exception = False
                self.active = True
                self.save()
            except IntegrityError:
                original_feed = Feed.objects.get(feed_address=feed_address)
                original_feed.has_feed_exception = False
                original_feed.active = True
                original_feed.save()
                merge_feeds(original_feed.pk, self.pk)

        return not not feed_address
Exemplo n.º 3
0
def exception_change_feed_link(request):
    feed_id = request.POST['feed_id']
    feed = get_object_or_404(Feed, pk=feed_id)
    feed_link = request.POST['feed_link']
    code = -1
    
    if not feed.has_page_exception and not feed.has_feed_exception:
        logging.info(" ***********> [%s] Incorrect feed link change: %s" % (request.user, feed))
        # This Forbidden-403 throws an error, which sounds pretty good to me right now
        return HttpResponseForbidden()
    
    feed_address = feedfinder.feed(feed_link)
    if feed_address:
        code = 1
        feed.has_page_exception = False
        feed.active = True
        feed.fetched_once = False
        feed.feed_link = feed_link
        feed.feed_address = feed_address
        feed.next_scheduled_update = datetime.datetime.now()
        try:
            feed.save()
        except IntegrityError:
            original_feed = Feed.objects.get(feed_address=feed_address)
            original_feed.next_scheduled_update = datetime.datetime.now()
            original_feed.has_page_exception = False
            original_feed.active = True
            original_feed.save()
            merge_feeds(original_feed.pk, feed.pk)
    
    return {'code': code}
    
    
Exemplo n.º 4
0
    def get_feed_from_url(cls, url):
        feed = None
    
        def by_url(address):
            feed = cls.objects.filter(feed_address=address)
            if not feed:
                duplicate_feed = DuplicateFeed.objects.filter(duplicate_address=address).order_by('pk')
                if duplicate_feed:
                    feed = [duplicate_feed[0].feed]
                
            return feed
            
        url = urlnorm.normalize(url)
        feed = by_url(url)

        if feed:
            feed = feed[0]
        else:
            if feedfinder.isFeed(url):
                feed = cls.objects.create(feed_address=url)
                feed = feed.update()
            else:
                feed_finder_url = feedfinder.feed(url)
                if feed_finder_url:
                    feed = by_url(feed_finder_url)
                    if not feed:
                        feed = cls.objects.create(feed_address=feed_finder_url)
                        feed = feed.update()
                    else:
                        feed = feed[0]
                    
        return feed
Exemplo n.º 5
0
def fetch_address_from_page(url, existing_feed=None):
    from apps.rss_feeds.models import Feed, DuplicateFeed
    feed_finder_url = feedfinder.feed(url)
    if feed_finder_url:
        if existing_feed:
            if Feed.objects.filter(feed_address=feed_finder_url):
                return None
            existing_feed.feed_address = feed_finder_url
            existing_feed.save()
            feed = existing_feed
        else:
            duplicate_feed = DuplicateFeed.objects.filter(
                duplicate_address=feed_finder_url)
            if duplicate_feed:
                feed = [duplicate_feed[0].feed]
            else:
                feed = Feed.objects.filter(feed_address=feed_finder_url)
            if not feed:
                feed = Feed(feed_address=feed_finder_url)
                feed.save()
                feed.update()
                feed = Feed.objects.get(pk=feed.pk)
            else:
                feed = feed[0]
        return feed
Exemplo n.º 6
0
    def get_feed_from_url(cls, url):
        feed = None

        def by_url(address):
            feed = cls.objects.filter(feed_address=address)
            if not feed:
                duplicate_feed = DuplicateFeed.objects.filter(
                    duplicate_address=address).order_by('pk')
                if duplicate_feed:
                    feed = [duplicate_feed[0].feed]

            return feed

        url = urlnorm.normalize(url)
        feed = by_url(url)

        if feed:
            feed = feed[0]
        else:
            if feedfinder.isFeed(url):
                feed = cls.objects.create(feed_address=url)
                feed = feed.update()
            else:
                feed_finder_url = feedfinder.feed(url)
                if feed_finder_url:
                    feed = by_url(feed_finder_url)
                    if not feed:
                        feed = cls.objects.create(feed_address=feed_finder_url)
                        feed = feed.update()
                    else:
                        feed = feed[0]

        return feed
Exemplo n.º 7
0
def exception_change_feed_link(request):
    feed_id = request.POST['feed_id']
    feed = get_object_or_404(Feed, pk=feed_id)
    original_feed = feed
    feed_link = request.POST['feed_link']
    code = -1
    
    if feed.has_page_exception or feed.has_feed_exception:
        # Fix broken feed
        logging.user(request, "~FRFixing feed exception by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed_address = feedfinder.feed(feed_link)
        if feed_address:
            code = 1
            feed.has_page_exception = False
            feed.active = True
            feed.fetched_once = False
            feed.feed_link = feed_link
            feed.feed_address = feed_address
            feed.next_scheduled_update = datetime.datetime.utcnow()
            duplicate_feed = feed.save()
            if duplicate_feed:
                new_feed = Feed.objects.get(pk=duplicate_feed.pk)
                feed = new_feed
                new_feed.next_scheduled_update = datetime.datetime.utcnow()
                new_feed.has_page_exception = False
                new_feed.active = True
                new_feed.save()
    else:
        # Branch good feed
        logging.user(request, "~FRBranching feed by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed, _ = Feed.objects.get_or_create(feed_address=feed.feed_address, feed_link=feed_link)
        if feed.pk != original_feed.pk:
            try:
                feed.branch_from_feed = original_feed.branch_from_feed or original_feed
            except Feed.DoesNotExist:
                feed.branch_from_feed = original_feed
            feed.feed_link_locked = True
            feed.save()

    feed = feed.update()
    feed = Feed.objects.get(pk=feed.pk)

    usersub = UserSubscription.objects.get(user=request.user, feed=original_feed)
    usersub.switch_feed(feed, original_feed)
    usersub.calculate_feed_scores(silent=False)
    
    feed.update_all_statistics()
    
    feeds = {original_feed.pk: usersub.canonical(full=True)}
    return {'code': code, 'feeds': feeds}
Exemplo n.º 8
0
def fetch_address_from_page(url, existing_feed=None):
    from apps.rss_feeds.models import Feed
    feed_finder_url = feedfinder.feed(url)
    if feed_finder_url:
        if existing_feed:
            if Feed.objects.filter(feed_address=feed_finder_url):
                return None
            existing_feed.feed_address = feed_finder_url
            existing_feed.save()
            feed = existing_feed
        else:
            try:
                feed = Feed.objects.get(feed_address=feed_finder_url)
            except Feed.DoesNotExist:
                feed = Feed(feed_address=feed_finder_url)
                feed.save()
                feed.update()
        return feed
Exemplo n.º 9
0
def exception_change_feed_link(request):
    feed_id = request.POST['feed_id']
    feed = get_object_or_404(Feed, pk=feed_id)
    feed_link = request.POST['feed_link']
    code = -1

    if not feed.has_page_exception and not feed.has_feed_exception:
        logging.info(" ***> [%s] ~BRIncorrect feed link change: ~SB%s" %
                     (request.user, feed))
        # This Forbidden-403 throws an error, which sounds pretty good to me right now
        return HttpResponseForbidden()

    retry_feed = feed
    feed_address = feedfinder.feed(feed_link)
    if feed_address:
        code = 1
        feed.has_page_exception = False
        feed.active = True
        feed.fetched_once = False
        feed.feed_link = feed_link
        feed.feed_address = feed_address
        feed.next_scheduled_update = datetime.datetime.utcnow()
        duplicate_feed_id = feed.save()
        if duplicate_feed_id:
            original_feed = Feed.objects.get(pk=duplicate_feed_id)
            retry_feed = original_feed
            original_feed.next_scheduled_update = datetime.datetime.utcnow()
            original_feed.has_page_exception = False
            original_feed.active = True
            original_feed.save()

    logging.user(
        request.user,
        "~FRFixing feed exception by link: ~SB%s" % (retry_feed.feed_link))
    retry_feed.update()

    usersub = UserSubscription.objects.get(user=request.user, feed=retry_feed)
    usersub.calculate_feed_scores(silent=False)

    feeds = {feed.pk: usersub.canonical(full=True)}
    return {'code': code, 'feeds': feeds}
Exemplo n.º 10
0
def exception_change_feed_link(request):
    feed_id = request.POST['feed_id']
    feed = get_object_or_404(Feed, pk=feed_id)
    feed_link = request.POST['feed_link']
    code = -1
    
    if not feed.has_page_exception and not feed.has_feed_exception:
        logging.info(" ***> [%s] ~BRIncorrect feed link change: ~SB%s" % (request.user, feed))
        # This Forbidden-403 throws an error, which sounds pretty good to me right now
        return HttpResponseForbidden()
    
    retry_feed = feed
    feed_address = feedfinder.feed(feed_link)
    if feed_address:
        code = 1
        feed.has_page_exception = False
        feed.active = True
        feed.fetched_once = False
        feed.feed_link = feed_link
        feed.feed_address = feed_address
        feed.next_scheduled_update = datetime.datetime.utcnow()
        duplicate_feed_id = feed.save()
        if duplicate_feed_id:
            original_feed = Feed.objects.get(pk=duplicate_feed_id)
            retry_feed = original_feed
            original_feed.next_scheduled_update = datetime.datetime.utcnow()
            original_feed.has_page_exception = False
            original_feed.active = True
            original_feed.save()
    
    logging.info(" ---> [%s] ~FRFixing feed exception by link: ~SB%s" % (request.user, retry_feed.feed_link))
    retry_feed.update()
    
    usersub = UserSubscription.objects.get(user=request.user, feed=retry_feed)
    usersub.calculate_feed_scores(silent=False)
    
    feeds = {feed.pk: usersub.canonical(full=True)}
    return {'code': code, 'feeds': feeds}
    
    
Exemplo n.º 11
0
def fetch_address_from_page(url, existing_feed=None):
    from apps.rss_feeds.models import Feed, DuplicateFeed
    feed_finder_url = feedfinder.feed(url)
    if feed_finder_url:
        if existing_feed:
            if Feed.objects.filter(feed_address=feed_finder_url):
                return None
            existing_feed.feed_address = feed_finder_url
            existing_feed.save()
            feed = existing_feed
        else:
            duplicate_feed = DuplicateFeed.objects.filter(duplicate_address=feed_finder_url)
            if duplicate_feed:
                feed = [duplicate_feed[0].feed]
            else:
                feed = Feed.objects.filter(feed_address=feed_finder_url)
            if not feed:
                feed = Feed(feed_address=feed_finder_url)
                feed.save()
                feed.update()
            else:
                feed = feed[0]
        return feed
Exemplo n.º 12
0
def exception_change_feed_link(request):
    feed_id = request.POST['feed_id']
    feed = get_object_or_404(Feed, pk=feed_id)
    original_feed = feed
    feed_link = request.POST['feed_link']
    timezone = request.user.profile.timezone
    code = -1
    
    if feed.has_page_exception or feed.has_feed_exception:
        # Fix broken feed
        logging.user(request, "~FRFixing feed exception by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed_address = feedfinder.feed(feed_link)
        if feed_address:
            code = 1
            feed.has_page_exception = False
            feed.active = True
            feed.fetched_once = False
            feed.feed_link = feed_link
            feed.feed_address = feed_address
            duplicate_feed = feed.schedule_feed_fetch_immediately()
            if duplicate_feed:
                new_feed = Feed.objects.get(pk=duplicate_feed.pk)
                feed = new_feed
                new_feed.schedule_feed_fetch_immediately()
                new_feed.has_page_exception = False
                new_feed.active = True
                new_feed.save()
    else:
        # Branch good feed
        logging.user(request, "~FRBranching feed by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed, _ = Feed.objects.get_or_create(feed_address=feed.feed_address, feed_link=feed_link)
        code = 1
        if feed.pk != original_feed.pk:
            try:
                feed.branch_from_feed = original_feed.branch_from_feed or original_feed
            except Feed.DoesNotExist:
                feed.branch_from_feed = original_feed
            feed.feed_link_locked = True
            feed.save()

    feed = feed.update()
    feed = Feed.get_by_id(feed.pk)

    try:
        usersub = UserSubscription.objects.get(user=request.user, feed=feed)
    except UserSubscription.DoesNotExist:
        usersubs = UserSubscription.objects.filter(user=request.user, feed=original_feed)
        if usersubs:
            usersub = usersubs[0]
            usersub.switch_feed(feed, original_feed)
        else:
            fetch_history = MFetchHistory.feed(feed_id, timezone=timezone)
            return {
                'code': -1,
                'feed_fetch_history': fetch_history['feed_fetch_history'],
                'page_fetch_history': fetch_history['page_fetch_history'],
                'push_history': fetch_history['push_history'],
            }
        
    usersub.calculate_feed_scores(silent=False)
    
    feed.update_all_statistics()
    classifiers = get_classifiers_for_user(usersub.user, feed_id=usersub.feed_id)
    
    if feed and feed.has_feed_exception:
        code = -1
    
    feeds = {
        original_feed.pk: usersub.canonical(full=True, classifiers=classifiers), 
    }
    fetch_history = MFetchHistory.feed(feed_id, timezone=timezone)
    return {
        'code': code, 
        'feeds': feeds, 
        'new_feed_id': usersub.feed_id,
        'feed_fetch_history': fetch_history['feed_fetch_history'],
        'page_fetch_history': fetch_history['page_fetch_history'],
        'push_history': fetch_history['push_history'],
    }
Exemplo n.º 13
0
def exception_change_feed_link(request):
    feed_id = request.POST['feed_id']
    feed = get_object_or_404(Feed, pk=feed_id)
    original_feed = feed
    feed_link = request.POST['feed_link']
    code = -1

    if feed.has_page_exception or feed.has_feed_exception:
        # Fix broken feed
        logging.user(
            request, "~FRFixing feed exception by link: ~SB%s~SN to ~SB%s" %
            (feed.feed_link, feed_link))
        feed_address = feedfinder.feed(feed_link)
        if feed_address:
            code = 1
            feed.has_page_exception = False
            feed.active = True
            feed.fetched_once = False
            feed.feed_link = feed_link
            feed.feed_address = feed_address
            feed.next_scheduled_update = datetime.datetime.utcnow()
            duplicate_feed = feed.save()
            if duplicate_feed:
                new_feed = Feed.objects.get(pk=duplicate_feed.pk)
                feed = new_feed
                new_feed.next_scheduled_update = datetime.datetime.utcnow()
                new_feed.has_page_exception = False
                new_feed.active = True
                new_feed.save()
    else:
        # Branch good feed
        logging.user(
            request, "~FRBranching feed by link: ~SB%s~SN to ~SB%s" %
            (feed.feed_link, feed_link))
        feed, _ = Feed.objects.get_or_create(feed_address=feed.feed_address,
                                             feed_link=feed_link)
        if feed.pk != original_feed.pk:
            try:
                feed.branch_from_feed = original_feed.branch_from_feed or original_feed
            except Feed.DoesNotExist:
                feed.branch_from_feed = original_feed
            feed.feed_link_locked = True
            feed.save()
            code = 1

    feed = feed.update()
    feed = Feed.objects.get(pk=feed.pk)

    usersub = UserSubscription.objects.get(user=request.user,
                                           feed=original_feed)
    if usersub:
        usersub.switch_feed(feed, original_feed)
    usersub = UserSubscription.objects.get(user=request.user, feed=feed)

    usersub.calculate_feed_scores(silent=False)

    feed.update_all_statistics()
    classifiers = get_classifiers_for_user(usersub.user, usersub.feed.pk)

    feeds = {
        original_feed.pk: usersub.canonical(full=True,
                                            classifiers=classifiers),
    }
    return {
        'code': code,
        'feeds': feeds,
        'new_feed_id': usersub.feed.pk,
    }
Exemplo n.º 14
0
def exception_change_feed_link(request):
    feed_id = request.POST['feed_id']
    feed = get_object_or_404(Feed, pk=feed_id)
    original_feed = feed
    feed_link = request.POST['feed_link']
    timezone = request.user.profile.timezone
    code = -1
    
    if feed.has_page_exception or feed.has_feed_exception:
        # Fix broken feed
        logging.user(request, "~FRFixing feed exception by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed_address = feedfinder.feed(feed_link)
        if feed_address:
            code = 1
            feed.has_page_exception = False
            feed.active = True
            feed.fetched_once = False
            feed.feed_link = feed_link
            feed.feed_address = feed_address
            duplicate_feed = feed.schedule_feed_fetch_immediately()
            if duplicate_feed:
                new_feed = Feed.objects.get(pk=duplicate_feed.pk)
                feed = new_feed
                new_feed.schedule_feed_fetch_immediately()
                new_feed.has_page_exception = False
                new_feed.active = True
                new_feed.save()
    else:
        # Branch good feed
        logging.user(request, "~FRBranching feed by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed, _ = Feed.objects.get_or_create(feed_address=feed.feed_address, feed_link=feed_link)
        code = 1
        if feed.pk != original_feed.pk:
            try:
                feed.branch_from_feed = original_feed.branch_from_feed or original_feed
            except Feed.DoesNotExist:
                feed.branch_from_feed = original_feed
            feed.feed_link_locked = True
            feed.save()

    feed = feed.update()
    feed = Feed.get_by_id(feed.pk)

    try:
        usersub = UserSubscription.objects.get(user=request.user, feed=feed)
    except UserSubscription.DoesNotExist:
        usersubs = UserSubscription.objects.filter(user=request.user, feed=original_feed)
        if usersubs:
            usersub = usersubs[0]
            usersub.switch_feed(feed, original_feed)
        else:
            fetch_history = MFetchHistory.feed(feed_id, timezone=timezone)
            return {
                'code': -1,
                'feed_fetch_history': fetch_history['feed_fetch_history'],
                'page_fetch_history': fetch_history['page_fetch_history'],
                'push_history': fetch_history['push_history'],
            }
        
    usersub.calculate_feed_scores(silent=False)
    
    feed.update_all_statistics()
    classifiers = get_classifiers_for_user(usersub.user, feed_id=usersub.feed_id)
    
    if feed and feed.has_feed_exception:
        code = -1
    
    feeds = {
        original_feed.pk: usersub.canonical(full=True, classifiers=classifiers), 
    }
    fetch_history = MFetchHistory.feed(feed_id, timezone=timezone)
    return {
        'code': code, 
        'feeds': feeds, 
        'new_feed_id': usersub.feed_id,
        'feed_fetch_history': fetch_history['feed_fetch_history'],
        'page_fetch_history': fetch_history['page_fetch_history'],
        'push_history': fetch_history['push_history'],
    }
Exemplo n.º 15
0
def exception_change_feed_link(request):
    feed_id = request.POST["feed_id"]
    feed = get_object_or_404(Feed, pk=feed_id)
    original_feed = feed
    feed_link = request.POST["feed_link"]
    code = -1

    if feed.has_page_exception or feed.has_feed_exception:
        # Fix broken feed
        logging.user(request, "~FRFixing feed exception by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed_address = feedfinder.feed(feed_link)
        if feed_address:
            code = 1
            feed.has_page_exception = False
            feed.active = True
            feed.fetched_once = False
            feed.feed_link = feed_link
            feed.feed_address = feed_address
            feed.next_scheduled_update = datetime.datetime.utcnow()
            duplicate_feed = feed.save()
            if duplicate_feed:
                new_feed = Feed.objects.get(pk=duplicate_feed.pk)
                feed = new_feed
                new_feed.next_scheduled_update = datetime.datetime.utcnow()
                new_feed.has_page_exception = False
                new_feed.active = True
                new_feed.save()
    else:
        # Branch good feed
        logging.user(request, "~FRBranching feed by link: ~SB%s~SN to ~SB%s" % (feed.feed_link, feed_link))
        feed, _ = Feed.objects.get_or_create(feed_address=feed.feed_address, feed_link=feed_link)
        if feed.pk != original_feed.pk:
            try:
                feed.branch_from_feed = original_feed.branch_from_feed or original_feed
            except Feed.DoesNotExist:
                feed.branch_from_feed = original_feed
            feed.feed_link_locked = True
            feed.save()
            code = 1

    feed = feed.update()
    feed = Feed.get_by_id(feed.pk)

    try:
        usersub = UserSubscription.objects.get(user=request.user, feed=feed)
    except UserSubscription.DoesNotExist:
        usersubs = UserSubscription.objects.filter(user=request.user, feed=original_feed)
        if usersubs:
            usersub = usersubs[0]
            usersub.switch_feed(feed, original_feed)
        else:
            return {"code": -1}

    usersub.calculate_feed_scores(silent=False)

    feed.update_all_statistics()
    classifiers = get_classifiers_for_user(usersub.user, feed_id=usersub.feed_id)

    if feed and feed.has_feed_exception:
        code = -1

    feeds = {original_feed.pk: usersub.canonical(full=True, classifiers=classifiers)}
    return {"code": code, "feeds": feeds, "new_feed_id": usersub.feed_id}