Beispiel #1
0
def feed_entry_publish(feed_type, feed_id, entry_id):
    """Get a feed"""
    logger.info('Manually publishing Feed:%s Entry: %s', feed_id, entry_id)

    key = ndb.Key(urlsafe=entry_id)
    feed = FEED_TYPE_TO_CLASS[feed_type].get_by_id(feed_id, parent=g.user.key)
    if not (feed and key.parent() == feed.key):
        return jsonify_error(message="Can't find that feed")

    entry = key.get()
    if not entry:
        return jsonify_error(message="Can't find that entry")

    publish_entry(entry, feed, ignore_publish_state=True).get_result()
    entry.overflow = False
    entry.put()

    return jsonify(status='ok')
Beispiel #2
0
def feed_entry_publish(feed_type, feed_id, entry_id):
    """Get a feed"""
    logger.info('Manually publishing Feed:%s Entry: %s', feed_id, entry_id)

    key = ndb.Key(urlsafe=entry_id)
    feed = FEED_TYPE_TO_CLASS[feed_type].get_by_id(feed_id, parent=g.user.key)
    if not (feed and key.parent() == feed.key):
        return jsonify_error(message="Can't find that feed")

    entry = key.get()
    if not entry:
        return jsonify_error(message="Can't find that entry")

    publish_entry(entry, feed, ignore_publish_state=True).get_result()
    entry.overflow = False
    entry.put()

    return jsonify(status='ok')
Beispiel #3
0
def email_to_feed(email):
    logger.info('Email: %s', email)
    account, _ = email.split('@', 1)
    logger.info('Account: %s', account)
    unique_key, feed_type, version = account.split('_')
    feed_type, version = map(int, (feed_type, version))
    logger.info('unique_key: %s feed_type:%s version:%s', unique_key, feed_type, version)
    feed = FEED_TYPE_TO_CLASS[feed_type].for_email(unique_key)
    logger.info('Found feed: %s', feed)
    mail_message = mail.InboundEmailMessage(request.stream.read())
    entry = yield feed.create_entry_from_mail(mail_message)
    yield publish_entry(entry, feed)

    raise ndb.Return(jsonify(status='ok'))
Beispiel #4
0
def email_to_feed(email):
    logger.info("Email: %s", email)
    account, _ = email.split("@", 1)
    logger.info("Account: %s", account)
    unique_key, feed_type, version = account.split("_")
    feed_type, version = map(int, (feed_type, version))
    logger.info("unique_key: %s feed_type:%s version:%s", unique_key, feed_type, version)
    feed = FEED_TYPE_TO_CLASS[feed_type].for_email(unique_key)
    logger.info("Found feed: %s", feed)
    mail_message = mail.InboundEmailMessage(request.stream.read())
    entry = yield feed.create_entry_from_mail(mail_message)
    yield publish_entry(entry, feed)

    raise ndb.Return(jsonify(status="ok"))
Beispiel #5
0
    def publish_for_feed(cls, feed, skip_queue=False):
        if not feed:
            logger.info("Asked to publish for a non-exsistant feed")
            raise ndb.Return(0)

        minutes_schedule = DEFAULT_PERIOD_SCHEDULE
        max_stories_to_publish = MAX_STORIES_PER_PERIOD
        if feed.manual_control:
            minutes_schedule = feed.schedule_period
            max_stories_to_publish = feed.max_stories_per_period

        if feed.dump_excess_in_period:
            max_stories_to_publish = 1

        # How many stories have been published in the last period_length
        now = datetime.now()
        period_ago = now - timedelta(minutes=minutes_schedule)
        lastest_published_entries = yield cls.latest_published(
            feed, since=period_ago).count_async()
        max_stories_to_publish = max_stories_to_publish - lastest_published_entries
        entries_posted = 0
        # If we still have time left in this period publish some more.
        if max_stories_to_publish > 0 or skip_queue:
            # If we are skipping the queue
            if skip_queue:
                max_stories_to_publish = max_stories_to_publish or 1

            latest_entries = yield cls.latest_unpublished(feed).fetch_async(
                max_stories_to_publish + 1)

            more_to_publish = False
            if len(latest_entries) > max_stories_to_publish:
                more_to_publish = True
                latest_entries = latest_entries[0:max_stories_to_publish]

            for entry in latest_entries:
                yield publish_entry(entry, feed)
                entries_posted += 1

            if not more_to_publish:
                feed.is_dirty = False
                yield feed.put_async()

            if more_to_publish and feed.dump_excess_in_period:
                yield cls.drain_queue(feed)

        raise ndb.Return(entries_posted)
Beispiel #6
0
    def publish_for_feed(cls, feed, skip_queue=False):
        if not feed:
            logger.info("Asked to publish for a non-exsistant feed")
            raise ndb.Return(0)

        minutes_schedule = DEFAULT_PERIOD_SCHEDULE
        max_stories_to_publish = MAX_STORIES_PER_PERIOD
        if feed.manual_control:
            minutes_schedule = feed.schedule_period
            max_stories_to_publish = feed.max_stories_per_period

        if feed.dump_excess_in_period:
            max_stories_to_publish = 1

        # How many stories have been published in the last period_length
        now = datetime.now()
        period_ago = now - timedelta(minutes=minutes_schedule)
        lastest_published_entries = yield cls.latest_published(feed, since=period_ago).count_async()
        max_stories_to_publish = max_stories_to_publish - lastest_published_entries
        entries_posted = 0
        # If we still have time left in this period publish some more.
        if max_stories_to_publish > 0 or skip_queue:
            # If we are skipping the queue
            if skip_queue:
                max_stories_to_publish = max_stories_to_publish or 1

            latest_entries = yield cls.latest_unpublished(feed).fetch_async(max_stories_to_publish + 1)

            more_to_publish = False
            if len(latest_entries) > max_stories_to_publish:
                more_to_publish = True
                latest_entries = latest_entries[0: max_stories_to_publish]

            for entry in latest_entries:
                yield publish_entry(entry, feed)
                entries_posted += 1

            if not more_to_publish:
                feed.is_dirty = False
                yield feed.put_async()

            if more_to_publish and feed.dump_excess_in_period:
                yield cls.drain_queue(feed)

        raise ndb.Return(entries_posted)