Exemplo n.º 1
0
def store_rds(keywords):
    """
    将keywords存入redis数据库
    :param keywords: 需存入redis的关键字
    :return None:
    数据存储在硬盘上(每3天进行清空)
    """
    # lambda rds: rds.incr(keywords) \
    # if rds.get(keywords) else rds.set(keywords, 1)
    if rds.get(keywords):
        count = int(rds.get(keywords))
        count += 1
        rds.set(keywords, count)
    else:
        rds.set(keywords, 1)
    rds.save()
Exemplo n.º 2
0
def hot():
    """
    返回最热的10个搜索词
    """
    words = rds.keys()
    hot_words = sorted(words, key=lambda w: int(rds.get(w)), reverse=True)[:10]
    return json.dumps(hot_words), 200
Exemplo n.º 3
0
def hot():
    """
    返回最热的10个搜索词
    """
    words = rds.keys()
    hot_words = sorted(words, key=lambda w: int(rds.get(w)), reverse=True)[:10]
    return json.dumps(hot_words), 200
Exemplo n.º 4
0
def search():
    """
    搜索API
    """
    keywords = request.args.get('keywords')
    page = request.args.get('page') or '1'
    per_page = request.args.get('per_page') or '20'
    main_cat = request.args.get('main_cat') or '0'
    ts_cat = request.args.get('ts_cat') or '0'
    # 搜索条件匹配
    results = category_catch(keywords, int(main_cat), int(ts_cat))
    # 热搜词存储
    rds.set(keywords, 1) \
        if rds.get(keywords) is None \
        else rds.incr(keywords)
    # 对结果集分页返回返回
    pagination_lit = pagination(results, int(page), int(per_page))
    current = pagination_lit[0]
    next_page = pagination_lit[1][0]
    last_page = pagination_lit[1][1]
    return json.dumps(
        current,
        ensure_ascii=False,
        indent=1
    ), 200, {
        'link': '<%s>; rel="next", <%s>; rel="last"' % (next_page, last_page)}
Exemplo n.º 5
0
def search():
    """
    搜索API
    """
    keywords = request.args.get('keywords')
    page = request.args.get('page') or '1'
    per_page = request.args.get('per_page') or '20'
    main_cat = request.args.get('main_cat') or '0'
    ts_cat = request.args.get('ts_cat') or '0'
    # 搜索条件匹配
    results = category_catch(keywords, int(main_cat), int(ts_cat))
    # 热搜词存储
    rds.set(keywords, 1) \
        if rds.get(keywords) is None \
        else rds.incr(keywords)
    # 对结果集分页返回返回
    pagination_lit = pagination(results, int(page), int(per_page))
    current = pagination_lit[0]
    next_page = pagination_lit[1][0]
    last_page = pagination_lit[1][1]
    return json.dumps(current, ensure_ascii=False, indent=1), 200, {
        'link': '<%s>; rel="next", <%s>; rel="last"' % (next_page, last_page)
    }