Exemple #1
0
def get_news_feed():
    person_id = request.args.get("person_id", None)
    order = request.args.get("order", "date")  # [date, likes]
    # page = request.args.get("page", 1)
    # limit = request.args.get("limit", 10)
    # if limit > 10 or limit <= 0:
    #     limit = 10
    if person_id:
        try:
            if order == "date":
                query = Post.select(Post.post_id, Post.author, Post.text, Post.pic_url, Post.date, Post.latitude, Post.longitude, Post.likes, Post.comments)\
                    .where(Post.author == person_id, Post.is_deleted == False)\
                    .order_by(Post.date.desc())\
                    .tuples()
            else:
                query = Post.select(Post.post_id, Post.author, Post.text, Post.pic_url, Post.date, Post.latitude, Post.longitude, Post.likes, Post.comments)\
                    .where(Post.author == person_id, Post.is_deleted == False)\
                    .order_by(Post.likes.desc())\
                    .tuples()
        except DoesNotExist:
            query = []
        res = prepare_feed_from_query_result(query)
        return json.dumps(res)
    else:
        return json.dumps({"message": "This person does not exist"})
Exemple #2
0
def get_news_feed():
    person_id = request.args.get("person_id", None)
    order = request.args.get("order", "date")  # [date, likes]
    # page = request.args.get("page", 1)
    # limit = request.args.get("limit", 10)
    # if limit > 10 or limit <= 0:
    #     limit = 10
    if person_id:
        try:
            if order == "date":
                query = Post.select(Post.post_id, Post.author, Post.text, Post.pic_url, Post.date, Post.latitude, Post.longitude, Post.likes, Post.comments)\
                    .where(Post.author == person_id, Post.is_deleted == False)\
                    .order_by(Post.date.desc())\
                    .tuples()
            else:
                query = Post.select(Post.post_id, Post.author, Post.text, Post.pic_url, Post.date, Post.latitude, Post.longitude, Post.likes, Post.comments)\
                    .where(Post.author == person_id, Post.is_deleted == False)\
                    .order_by(Post.likes.desc())\
                    .tuples()
        except DoesNotExist:
            query = []
        res = prepare_feed_from_query_result(query)
        return json.dumps(res)
    else:
        return json.dumps({"message": "This person does not exist"})
Exemple #3
0
def get_global_feed():
    person_id = request.args.get(VKID_NAME)
    # TODO: add search by lat & lon
    sql = """
SELECT p.`post_id`, p.`author_id`, p.`text`, p.`pic_url`, p.`date`, p.`latitude`, p.`longitude`, p.`likes`, p.`comments` FROM `post` p
JOIN `personsubscriptions` ps ON p.`author_id` = ps.`owner_id`
WHERE ps.`follower_id` = %s AND p.`is_deleted` IS NOT TRUE
"""
    query = database.execute_sql(sql, person_id)
    res = prepare_feed_from_query_result(query)
    return json.dumps(res)
Exemple #4
0
def get_global_feed():
    person_id = request.args.get(VKID_NAME)
    # TODO: add search by lat & lon
    sql = """
SELECT p.`post_id`, p.`author_id`, p.`text`, p.`pic_url`, p.`date`, p.`latitude`, p.`longitude`, p.`likes`, p.`comments` FROM `post` p
JOIN `personsubscriptions` ps ON p.`author_id` = ps.`owner_id`
WHERE ps.`follower_id` = %s AND p.`is_deleted` IS NOT TRUE
"""
    query = database.execute_sql(sql, person_id)
    res = prepare_feed_from_query_result(query)
    return json.dumps(res)
Exemple #5
0
def get_map():
    longitude = request.args.get("longitude", None)
    latitude = request.args.get("latitude", None)
    distance = request.args.get("distance", None)
    if longitude and latitude and distance:
        # sql = "CALL geodist({0}, {1}, {2});".format(longitude, latitude, distance)  # F**k this
        sql = """
SELECT p.`post_id`, p.`author_id`, p.`text`, p.`pic_url`, p.`date`, p.`latitude`, p.`longitude`, p.`likes`, p.`comments` FROM `post` p
WHERE p.`date` BETWEEN DATE_SUB(NOW(), INTERVAL 1 DAY) AND NOW() ORDER BY p.`date` DESC LIMIT 7
"""
        query = database.execute_sql(sql)
        res = prepare_feed_from_query_result(query)
        return json.dumps(res)
    else:
        return json.dumps({"message": "Parameters 'latitude', 'longitude' and 'distance' are required"})
Exemple #6
0
def get_map():
    longitude = request.args.get("longitude", None)
    latitude = request.args.get("latitude", None)
    distance = request.args.get("distance", None)
    if longitude and latitude and distance:
        # sql = "CALL geodist({0}, {1}, {2});".format(longitude, latitude, distance)  # F**k this
        sql = """
SELECT p.`post_id`, p.`author_id`, p.`text`, p.`pic_url`, p.`date`, p.`latitude`, p.`longitude`, p.`likes`, p.`comments` FROM `post` p
WHERE p.`date` BETWEEN DATE_SUB(NOW(), INTERVAL 1 DAY) AND NOW() ORDER BY p.`date` DESC LIMIT 7
"""
        query = database.execute_sql(sql)
        res = prepare_feed_from_query_result(query)
        return json.dumps(res)
    else:
        return json.dumps({
            "message":
            "Parameters 'latitude', 'longitude' and 'distance' are required"
        })