当前位置: 首页>>代码示例>>Python>>正文


Python MFetchHistory.add方法代码示例

本文整理汇总了Python中apps.rss_feeds.models.MFetchHistory.add方法的典型用法代码示例。如果您正苦于以下问题:Python MFetchHistory.add方法的具体用法?Python MFetchHistory.add怎么用?Python MFetchHistory.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apps.rss_feeds.models.MFetchHistory的用法示例。


在下文中一共展示了MFetchHistory.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: receive_newsletter

# 需要导入模块: from apps.rss_feeds.models import MFetchHistory [as 别名]
# 或者: from apps.rss_feeds.models.MFetchHistory import add [as 别名]
 def receive_newsletter(self, params):
     user = self.user_from_email(params['recipient'])
     if not user:
         return
     
     sender_name, sender_username, sender_domain = self.split_sender(params['from'])
     feed_address = self.feed_address(user, "%[email protected]%s" % (sender_username, sender_domain))
     
     usf = UserSubscriptionFolders.objects.get(user=user)
     usf.add_folder('', 'Newsletters')
     
     try:
         feed = Feed.objects.get(feed_address=feed_address)
     except Feed.DoesNotExist:
         feed = Feed.objects.create(feed_address=feed_address, 
                                    feed_link='http://' + sender_domain,
                                    feed_title=sender_name,
                                    fetched_once=True,
                                    known_good=True)
         feed.update()
         logging.user(user, "~FCCreating newsletter feed: ~SB%s" % (feed))
         r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
         r.publish(user.username, 'reload:%s' % feed.pk)
     try:
         usersub = UserSubscription.objects.get(user=user, feed=feed)
     except UserSubscription.DoesNotExist:
         _, _, usersub = UserSubscription.add_subscription(
             user=user, 
             feed_address=feed_address,
             folder='Newsletters'
         )
     
     story_hash = MStory.ensure_story_hash(params['signature'], feed.pk)
     story_params = {
         "story_feed_id": feed.pk,
         "story_date": datetime.datetime.fromtimestamp(int(params['timestamp'])),
         "story_title": params['subject'],
         "story_content": self.get_content(params),
         "story_author_name": escape(params['from']),
         "story_permalink": reverse('newsletter-story', 
                                    kwargs={'story_hash': story_hash}),
         "story_guid": params['signature'],
     }
     try:
         story = MStory.objects.get(story_hash=story_hash)
     except MStory.DoesNotExist:
         story = MStory(**story_params)
         story.save()
     
     usersub.needs_unread_recalc = True
     usersub.save()
     
     self.publish_to_subscribers(feed)
     
     MFetchHistory.add(feed_id=feed.pk, fetch_type='push')
     logging.user(user, "~FCNewsletter feed story: ~SB%s~SN / ~SB%s" % (story.story_title, feed))
     
     return story
开发者ID:670415613,项目名称:NewsBlur,代码行数:60,代码来源:models.py

示例2: push_callback

# 需要导入模块: from apps.rss_feeds.models import MFetchHistory [as 别名]
# 或者: from apps.rss_feeds.models.MFetchHistory import add [as 别名]
def push_callback(request, push_id):
    if request.method == 'GET':
        mode = request.GET['hub.mode']
        topic = request.GET['hub.topic']
        challenge = request.GET['hub.challenge']
        lease_seconds = request.GET.get('hub.lease_seconds')
        verify_token = request.GET.get('hub.verify_token', '')

        if mode == 'subscribe':
            if not verify_token.startswith('subscribe'):
                raise Http404
            subscription = get_object_or_404(PushSubscription,
                                             pk=push_id,
                                             topic=topic,
                                             verify_token=verify_token)
            subscription.verified = True
            subscription.set_expiration(int(lease_seconds))
            subscription.save()
            subscription.feed.setup_push()

            logging.debug('   ---> [%-30s] [%s] ~BBVerified PuSH' % (unicode(subscription.feed)[:30], subscription.feed_id))

            verified.send(sender=subscription)

        return HttpResponse(challenge, content_type='text/plain')
    elif request.method == 'POST':
        subscription = get_object_or_404(PushSubscription, pk=push_id)
        fetch_history = MFetchHistory.feed(subscription.feed_id)
        latest_push_date_delta = None
        if fetch_history and fetch_history.get('push_history'):
            latest_push = fetch_history['push_history'][0]['push_date']
            latest_push_date = datetime.datetime.strptime(latest_push, '%Y-%m-%d %H:%M:%S')
            latest_push_date_delta = datetime.datetime.now() - latest_push_date
            if latest_push_date > datetime.datetime.now() - datetime.timedelta(minutes=1):
                logging.debug('   ---> [%-30s] ~SN~FBSkipping feed fetch, pushed %s seconds ago' % (unicode(subscription.feed)[:30], latest_push_date_delta.seconds))
                return HttpResponse('Slow down, you just pushed %s seconds ago...' % latest_push_date_delta.seconds, status=429)
                
        # XXX TODO: Optimize this by removing feedparser. It just needs to find out
        # the hub_url or topic has changed. ElementTree could do it.
        if random.random() < 0.1:
            parsed = feedparser.parse(request.raw_post_data)
            subscription.check_urls_against_pushed_data(parsed)

        # Don't give fat ping, just fetch.
        # subscription.feed.queue_pushed_feed_xml(request.raw_post_data)
        if subscription.feed.active_premium_subscribers >= 1:
            subscription.feed.queue_pushed_feed_xml("Fetch me", latest_push_date_delta=latest_push_date_delta)
            MFetchHistory.add(feed_id=subscription.feed_id, 
                              fetch_type='push')
        else:
            logging.debug('   ---> [%-30s] ~FBSkipping feed fetch, no actives: %s' % (unicode(subscription.feed)[:30], subscription.feed))
        
        return HttpResponse('OK')
    return Http404
开发者ID:1059232202,项目名称:NewsBlur,代码行数:56,代码来源:views.py

示例3: push_callback

# 需要导入模块: from apps.rss_feeds.models import MFetchHistory [as 别名]
# 或者: from apps.rss_feeds.models.MFetchHistory import add [as 别名]
def push_callback(request, push_id):
    if request.method == 'GET':
        mode = request.GET['hub.mode']
        topic = request.GET['hub.topic']
        challenge = request.GET['hub.challenge']
        lease_seconds = request.GET.get('hub.lease_seconds')
        verify_token = request.GET.get('hub.verify_token', '')

        if mode == 'subscribe':
            if not verify_token.startswith('subscribe'):
                raise Http404
            subscription = get_object_or_404(PushSubscription,
                                             pk=push_id,
                                             topic=topic,
                                             verify_token=verify_token)
            subscription.verified = True
            subscription.set_expiration(int(lease_seconds))
            subscription.save()
            subscription.feed.setup_push()

            logging.debug('   ---> [%-30s] [%s] ~BBVerified PuSH' % (unicode(subscription.feed)[:30], subscription.feed_id))

            verified.send(sender=subscription)

        return HttpResponse(challenge, content_type='text/plain')
    elif request.method == 'POST':
        subscription = get_object_or_404(PushSubscription, pk=push_id)
        # XXX TODO: Optimize this by removing feedparser. It just needs to find out
        # the hub_url or topic has changed. ElementTree could do it.
        if random.random() < 0.1:
            parsed = feedparser.parse(request.raw_post_data)
            subscription.check_urls_against_pushed_data(parsed)

        # Don't give fat ping, just fetch.
        # subscription.feed.queue_pushed_feed_xml(request.raw_post_data)
        if subscription.feed.active_premium_subscribers >= 1:
            subscription.feed.queue_pushed_feed_xml("Fetch me")
            MFetchHistory.add(feed_id=subscription.feed_id, 
                              fetch_type='push')
        else:
            logging.debug('   ---> [%-30s] ~FBSkipping feed fetch, no actives: %s' % (unicode(subscription.feed)[:30], subscription.feed))
        
        return HttpResponse('')
    return Http404
开发者ID:1761461582,项目名称:NewsBlur,代码行数:46,代码来源:views.py

示例4: receive_newsletter

# 需要导入模块: from apps.rss_feeds.models import MFetchHistory [as 别名]
# 或者: from apps.rss_feeds.models.MFetchHistory import add [as 别名]
    def receive_newsletter(self, params):
        user = self._user_from_email(params['recipient'])
        if not user:
            return
        
        sender_name, sender_username, sender_domain = self._split_sender(params['from'])
        feed_address = self._feed_address(user, "%[email protected]%s" % (sender_username, sender_domain))
        
        try:
            usf = UserSubscriptionFolders.objects.get(user=user)
        except UserSubscriptionFolders.DoesNotExist:
            logging.user(user, "~FRUser does not have a USF, ignoring newsletter.")
            return
        usf.add_folder('', 'Newsletters')
        
        try:
            feed = Feed.objects.get(feed_address=feed_address)
        except Feed.DoesNotExist:
            feed = Feed.objects.create(feed_address=feed_address, 
                                       feed_link='http://' + sender_domain,
                                       feed_title=sender_name,
                                       fetched_once=True,
                                       known_good=True)
            feed.update()
            logging.user(user, "~FCCreating newsletter feed: ~SB%s" % (feed))
            r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
            r.publish(user.username, 'reload:%s' % feed.pk)
            self._check_if_first_newsletter(user)
        
        feed.last_update = datetime.datetime.now()
        feed.last_story_date = datetime.datetime.now()
        feed.save()
        
        if feed.feed_title != sender_name:
            feed.feed_title = sender_name
            feed.save()
        
        try:
            usersub = UserSubscription.objects.get(user=user, feed=feed)
        except UserSubscription.DoesNotExist:
            _, _, usersub = UserSubscription.add_subscription(
                user=user, 
                feed_address=feed_address,
                folder='Newsletters'
            )
            r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
            r.publish(user.username, 'reload:feeds')            
        
        story_hash = MStory.ensure_story_hash(params['signature'], feed.pk)
        story_content = self._get_content(params)
        plain_story_content = self._get_content(params, force_plain=True)
        if len(plain_story_content) > len(story_content):
            story_content = plain_story_content
        story_content = self._clean_content(story_content)
        story_params = {
            "story_feed_id": feed.pk,
            "story_date": datetime.datetime.fromtimestamp(int(params['timestamp'])),
            "story_title": params['subject'],
            "story_content": story_content,
            "story_author_name": params['from'],
            "story_permalink": "https://%s%s" % (
                                    Site.objects.get_current().domain,
                                    reverse('newsletter-story', 
                                            kwargs={'story_hash': story_hash})),
            "story_guid": params['signature'],
        }

        try:
            story = MStory.objects.get(story_hash=story_hash)
        except MStory.DoesNotExist:
            story = MStory(**story_params)
            story.save()
        
        usersub.needs_unread_recalc = True
        usersub.save()
        
        self._publish_to_subscribers(feed, story.story_hash)
        
        MFetchHistory.add(feed_id=feed.pk, fetch_type='push')
        logging.user(user, "~FCNewsletter feed story: ~SB%s~SN / ~SB%s" % (story.story_title, feed))
        
        return story
开发者ID:MilenkoM,项目名称:NewsBlur,代码行数:84,代码来源:models.py

示例5: receive_newsletter

# 需要导入模块: from apps.rss_feeds.models import MFetchHistory [as 别名]
# 或者: from apps.rss_feeds.models.MFetchHistory import add [as 别名]
    def receive_newsletter(self, params):
        user = self.user_from_email(params["recipient"])
        if not user:
            return

        sender_name, sender_username, sender_domain = self.split_sender(params["from"])
        feed_address = self.feed_address(user, "%[email protected]%s" % (sender_username, sender_domain))

        usf = UserSubscriptionFolders.objects.get(user=user)
        usf.add_folder("", "Newsletters")

        try:
            feed = Feed.objects.get(feed_address=feed_address)
        except Feed.DoesNotExist:
            feed = Feed.objects.create(
                feed_address=feed_address,
                feed_link="http://" + sender_domain,
                feed_title=sender_name,
                fetched_once=True,
                known_good=True,
            )
            feed.update()
            logging.user(user, "~FCCreating newsletter feed: ~SB%s" % (feed))
            r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
            r.publish(user.username, "reload:%s" % feed.pk)

        if feed.feed_title != sender_name:
            feed.feed_title = sender_name
            feed.save()

        try:
            usersub = UserSubscription.objects.get(user=user, feed=feed)
        except UserSubscription.DoesNotExist:
            _, _, usersub = UserSubscription.add_subscription(
                user=user, feed_address=feed_address, folder="Newsletters"
            )

        story_hash = MStory.ensure_story_hash(params["signature"], feed.pk)
        story_content = self.get_content(params)
        story_content = self.clean_content(story_content)
        story_params = {
            "story_feed_id": feed.pk,
            "story_date": datetime.datetime.fromtimestamp(int(params["timestamp"])),
            "story_title": params["subject"],
            "story_content": story_content,
            "story_author_name": params["from"],
            "story_permalink": "https://%s%s"
            % (Site.objects.get_current().domain, reverse("newsletter-story", kwargs={"story_hash": story_hash})),
            "story_guid": params["signature"],
        }
        try:
            story = MStory.objects.get(story_hash=story_hash)
        except MStory.DoesNotExist:
            story = MStory(**story_params)
            story.save()

        usersub.needs_unread_recalc = True
        usersub.save()

        self.publish_to_subscribers(feed)

        MFetchHistory.add(feed_id=feed.pk, fetch_type="push")
        logging.user(user, "~FCNewsletter feed story: ~SB%s~SN / ~SB%s" % (story.story_title, feed))

        return story
开发者ID:jklmn13,项目名称:NewsBlur,代码行数:67,代码来源:models.py


注:本文中的apps.rss_feeds.models.MFetchHistory.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。