Beispiel #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"})
Beispiel #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"})
Beispiel #3
0
def demo_add_comment(author_id, post_id):
    _, words_amount, text = generate_sentence()
    try:
        if author_id:
            Person.get(Person.vkid == author_id)
        else:
            all_pers = Person.select(Person.vkid)
            count = all_pers.count() - 1
            author_id = all_pers[random.randint(0, count)]

        if post_id:
            p = Post.get(Post.post_id == post_id)
        else:
            all_posts = Post.select()
            count = all_posts.count() - 1
            p = all_posts[random.randint(0, count)]
            p.comments += 1
            p.save()
        Comment.create(post=p, author=author_id, text=text)
        return True
    except DoesNotExist:
        return False
Beispiel #4
0
def demo_add_comment(author_id, post_id):
    _, words_amount, text = generate_sentence()
    try:
        if author_id:
            Person.get(Person.vkid == author_id)
        else:
            all_pers = Person.select(Person.vkid)
            count = all_pers.count() - 1
            author_id = all_pers[random.randint(0, count)]

        if post_id:
            p = Post.get(Post.post_id == post_id)
        else:
            all_posts = Post.select()
            count = all_posts.count() - 1
            p = all_posts[random.randint(0, count)]
            p.comments += 1
            p.save()
        Comment.create(post=p, author=author_id, text=text)
        return True
    except DoesNotExist:
        return False