Beispiel #1
0
def search_tag_names_letter(letter, page=0): #OK
    """
    Gets the tags starting by the given letter.
    By default retrieves all the matching elements.
    - Support for pagination by providing a positive 'page' value.
      Pagination works with yil-pil's pagination configuration.
    """
    if len(str(letter)) == 1:
        if page == 0:
            debug("SEARCH BY LETTER: " + letter)
            # Normal behaviour
            return db.zrangebyscore(SEARCH_TAGS_LETTER,
                                    ord(str(letter).upper()),
                                    ord(str(letter).upper())) # One score
        elif page > 0:
            # Pagination
            return _raw_paginate(db.zrangebyscore(SEARCH_TAGS_LETTER,
                                                  ord(str(letter).upper()),
                                                  ord(str(letter).upper())), page)
        else:
            # Bad request
            return None
    else:
        # Bad request, we are searching by a single letter.
        return None
Beispiel #2
0
def search_posts_user_date(username, date_ini, date_end, page=0):
    """
    Returns a list of posts wrote by the user at the given date interval.
    All dates must be provided in 'YYYYMMDD' format.
    - Pagination is enabled givin a positive 'page' value.
      Pagination works with yil-pil's pagination configuration.
    """
    if _is_user_created(username) \
    and len(str(date_ini)) == 8 and len(str(date_end)) == 8 \
    and int(date_end) >= int(date_ini) \
    and username != None and len(username) > 0:
        post_ids = db.zrangebyscore(username + APPEND_SEARCH_POST_TIMEDATE,
                                    date_ini, date_end)
        # Slice the array if pagination is requested
        if page > 0:
            post_ids = _raw_paginate(post_ids, page)
        results = []
        for post_id in post_ids:
            results.append(get_post(post_id))
        debug("SEARCH POSTS_USER_DATE returning: " + str(len(results)))
        return results
    else:
        # Bad request
        return None
Beispiel #3
0
def _alternative_score(tag_name):
    """ An alternaive way of checking the score of a tag. """
    result = db.zrangebyscore(POPULAR_TAGS, 0, 1, start=0,
                              num=API_MAX_UPDATES, withscores=True)
    result = [(name, score) for name, score in result if name == tag_name]
    return result[0][1] if result != None and len(result) > 0 else -1