コード例 #1
0
ファイル: manager.py プロジェクト: 7flying/yil-pil
def get_top_posts(page=0):
    """
    Returns the top posts.
    Pagination may be used, if it isn't, by default returns the first page.
    """
    result = db.zrevrangebyscore(POPULAR_TOP_POSTS, '+inf', 1,
                                 start=page * API_MAX_UPDATES,
                                 num=API_MAX_UPDATES, withscores=False)
    ret = []
    for post_id in result:
        ret.append(get_post(post_id))
    return ret
コード例 #2
0
ファイル: manager.py プロジェクト: 7flying/yil-pil
def get_popular_tags():
    """ Returns the most popular tags."""
    # zrevrangebyscore(name, max, min, start=None, num=None, withscores=False,...
    result = db.zrevrangebyscore(POPULAR_TAGS, '+inf', 1, start=0,
                                 num=API_MAX_UPDATES, withscores=True)
    good_format = []
    for name, score in result:
        dic = {}
        dic['name'] = name
        dic['num'] = int(score)
        good_format.append(dic)
    return good_format
コード例 #3
0
ファイル: manager.py プロジェクト: 7flying/yil-pil
def get_popular_posts(category, page=0):
    """
    Returns the most popular posts in a category.
    Pagination may be used, if it isn't, by default returns the first page.
    """
    category = category.upper()
    result = db.zrevrangebyscore(
        str(category) + APPEND_POPULAR_POSTS_CATEGORY,
        '+inf', 1, start=page * API_MAX_UPDATES, num=API_MAX_UPDATES,
        withscores=False)
    ret = []
    for post_id in result:
        ret.append(get_post(post_id))
    return ret