Пример #1
0
def most_kiked(offset=0, num_articles=10, sort=-1):
    client = get_mongo_client()
    collection = client.get_default_database()["articles"]
    query = {"k": {"$gt": 0}}
    articles = collection.find(query).sort("k", sort).skip(offset).limit(num_articles)

    close_mongo_client(client)
    return map(article_mapper, articles)
Пример #2
0
def latest(categories=None, offset=0, num_articles=30, sort=1):
    client = get_mongo_client()
    collection = client.get_default_database()["articles"]
    query = {"c": {"$in": categories}} if categories else {}
    articles = collection.find(query).sort("_id", sort).skip(offset).limit(num_articles)

    close_mongo_client(client)
    return map(article_mapper, articles)
Пример #3
0
def kik(article_id):
    success = True
    try:
        client = get_mongo_client()
        collection = client.get_default_database()["articles"]
        collection.update({"_id": ObjectId(article_id)}, {"$inc": {"k": 1}})
        close_mongo_client(client)
    except Exception as e:
        success = False

    return success
Пример #4
0
def most_kiked(offset=0, num_articles=10, sort=-1):
    client     = get_mongo_client()
    collection = client.get_default_database()['articles']
    query      = { 'k': {'$gt': 0} }
    articles   =  collection \
                    .find(query) \
                    .sort('k', sort) \
                    .skip(offset) \
                    .limit(num_articles) 

    close_mongo_client(client)
    return map(article_mapper, articles)    
Пример #5
0
def latest(categories=None, offset=0, num_articles=30, sort=1):
    client     = get_mongo_client()
    collection = client.get_default_database()['articles']
    query      = { 'c': { '$in': categories } } if categories else {}
    articles   =  collection \
                    .find(query) \
                    .sort('_id', sort)\
                    .skip(offset)\
                    .limit(num_articles)

    close_mongo_client(client)
    return map(article_mapper, articles)
Пример #6
0
def before(before_id, categories=None, num_articles=10, sort=-1):
    client = get_mongo_client()
    collection = client.get_default_database()["articles"]
    query = {"_id": {"$lt": ObjectId(before_id)}}

    if categories:
        query["c"] = {"$in": categories}

    articles = collection.find(query).sort("_id", sort).limit(num_articles)

    close_mongo_client(client)
    return map(article_mapper, articles)
Пример #7
0
def kik(article_id):
    success = True
    try:
        client     = get_mongo_client()
        collection = client.get_default_database()['articles']
        collection.update(
            { '_id'  : ObjectId(article_id) },
            { '$inc' : { 'k' : 1 } }
        )
        close_mongo_client(client)
    except Exception as e:
        success = False

    return success
Пример #8
0
def before(before_id, categories=None, num_articles=10, sort=-1):
    client     = get_mongo_client()
    collection = client.get_default_database()['articles']
    query      = { '_id': {'$lt': ObjectId(before_id)} }

    if categories:
        query['c'] = {'$in': categories}

    articles =  collection \
                .find(query) \
                .sort('_id', sort) \
                .limit(num_articles) 

    close_mongo_client(client)
    return map(article_mapper, articles)