Ejemplo n.º 1
0
def _search(keywords):
    import search
    hits = []
    results = search.fts.search(keywords, limit=10)
    db = database.Dao()
    try:
        for hit in results:
            try:
                news = db.get_news(hit['news_id'])
                text = util.extract_text(news[5])
                summary = hit.highlights('content', text=text, top=2)
                hits.append(dict(
                    image_public_url=news[8],
                    share_url=news[3],
                    date=news[4],
                    title=news[2],
                    summary=summary,
                ))
            except Exception, e:
                stack = traceback.format_exc()
                logging.error("one hit error: %s\n%s" % (e, stack))
    finally:
        db.close()

    return hits
Ejemplo n.º 2
0
def _get_news_list(date_str):
    dao = database.Dao()
    news_list = []
    try:
        wait_for_indexed_news_list = dao.select_news_list(date_str)
        for news in wait_for_indexed_news_list:
            news_list.append(dict(news_id=news[1], title=news[2],
                                  body=news[5]))
        return news_list
    finally:
        dao.close()
Ejemplo n.º 3
0
def _store_news_list(news_list):
    """将news_list保存到数据库中

    :param news_list:
    :return:
    """
    dao = database.Dao()
    try:
        for news in news_list:
            dao.insert(news['public_image_url'], news['date_str'],
                       news['news'])
    finally:
        dao.close()
Ejemplo n.º 4
0
def _get_news(date_str):
    news_list = []
    dao = database.Dao()
    try:
        newses = dao.select_news_list(date_str)
        if newses:
            for news in newses:
                news_list.append(dict(share_url=news[3],
                                      image_public_url=news[8],
                                      image_source=news[7],
                                      title=news[2]))
        return news_list
    finally:
        dao.close()
Ejemplo n.º 5
0
def _not_exists_news_ids(date_str, latest_news_ids):
    """找出所有不存在的news_ids

    :param date_str:
    :param latest_news_ids:
    :return:
    """
    dao = database.Dao()
    not_exists_news_ids = []
    try:
        exists_news_ids = [
            str(news[1]) for news in dao.select_news_list(date_str)
        ]
        for news_id in latest_news_ids:
            if str(news_id) not in exists_news_ids:
                not_exists_news_ids.append(news_id)
    finally:
        dao.close()
    return not_exists_news_ids