예제 #1
0
    def feed(self):
        news = [self.to_news(story) for story in Story.of(self.date)]

        feed = Feed()
        feed.news.extend([n for n in news if n])

        return feed
예제 #2
0
    def feed(self):
        pairs = Story.of(self.date)
        news = [self.to_news(pair) for pair in pairs]

        feed = Feed()
        feed.news.extend([n for n in news if n])

        return feed
예제 #3
0
def feed_for_date(date):
    stories = stories_for_date(date)
    documents = map(document_for_story, stories)
    pairs = list(zip(stories, documents))

    feed = Feed()
    feed.news.extend(
        filter(lambda news: len(news.questions) > 0,
               [_to_news(pair, date) for pair in pairs]))

    return feed
예제 #4
0
def search(keyword):
    criteria = {
        "$or": [
            {"title": _criteria_keyword_ignore_case(keyword)},
            {"questions.title": _criteria_keyword_ignore_case(keyword)},
        ]
    }

    feed = Feed()
    feed.news.extend(_news_list_to_feed(_query_collection(criteria)))

    return feed
예제 #5
0
def _feed_of(date):
    dt = DateTimeChina.parse(date)
    bypass_cache = request.GET.get('bypass_cache', '') == 'true'

    if dt is None or dt.is_before_birthday():
        return Feed().SerializeToString()

    if dt.is_after_current_date_in_china():
        date = DateTimeChina.current_date()

    if bypass_cache:
        feed = ZhihuDailyOfficial(date).feed()
    elif mongo.has_date_cached(date):
        feed = mongo.feed_for_date(date)
    else:
        feed = ZhihuDailyOfficial(date).feed()
        mongo.save_feed(feed)

    return feed.SerializeToString()
예제 #6
0
def feed_for_date(date):
    feed = Feed()
    feed.news.extend(_news_list_to_feed(_query_collection({'date': date})))

    return feed
예제 #7
0
def _empty_feed(date):
    feed = Feed()
    feed.date = date

    return feed