Пример #1
0
def get_post_info_params(cursor, post_info, related_list):
    user_info = post_info[4]
    thread_info = post_info[2]
    forum_info = post_info[5]
    for related in related_list:
        if related == 'user':
            user_info = get_user_info_external(cursor, post_info[4])
        elif related == 'thread':
            thread_info = get_thread_info_external(cursor, post_info[2])
        elif related == 'forum':
            forum_info = get_forum_info_external(cursor, post_info[5])

    resp = {
        "date": datetime.datetime.strftime(post_info[1], "%Y-%m-%d %H:%M:%S"),
        "dislikes": post_info[13],
        "forum": forum_info,
        "id": post_info[0],
        "isApproved": true_false_ret(post_info[7]),
        "isDeleted": true_false_ret(post_info[11]),
        "isEdited": true_false_ret(post_info[9]),
        "isHighlighted": true_false_ret(post_info[8]),
        "isSpam": true_false_ret(post_info[10]),
        "likes": post_info[12],
        "message": post_info[3],
        "parent": zero_check(post_info[6]),
        "points": post_info[14],
        "thread": thread_info,
        "user": user_info
    }
    return resp
Пример #2
0
def thread_details():
    conn = mysql.get_db()
    cursor = conn.cursor()
    if not request.args.get('thread'):
        return jsonify(code=3, response="Wrong request")

    thread_id = request.args.get('thread')
    try:
        cursor.execute("SELECT * FROM Thread WHERE id='%s'" % thread_id)
    except Exception:
        return jsonify(code=3, response="Wrong request")

    thread = cursor.fetchall()
    if not thread:
        return jsonify(code=3, response="No such thread")
    thread_info = thread[0]

    forum_info = thread_info[1]
    user_info = thread_info[4]
    related_list = request.args.getlist('related')

    for related in related_list:
        if related == 'user':
            user_info = get_user_info_external(cursor, thread_info[4])
        elif related == 'forum':
            forum_info = get_forum_info_external(cursor, thread_info[1])
        elif related == 'thread':
            return jsonify(code=3, response="Wrong request")

    num_posts = count_posts_in_thread(cursor, thread_id)
    if true_false_ret(thread_info[8]):
        num_posts = 0

    resp = {
        "id": thread_info[0],
        "forum": forum_info,
        "title": thread_info[2],
        "isClosed": true_false_ret(thread_info[3]),
        "user": user_info,
        "date": datetime.datetime.strftime(thread_info[5],
                                           "%Y-%m-%d %H:%M:%S"),
        "message": thread_info[6],
        "slug": thread_info[7],
        "isDeleted": true_false_ret(thread_info[8]),
        "likes": thread_info[9],
        "dislikes": thread_info[10],
        "points": thread_info[11],
        "posts": num_posts
    }
    return jsonify(code=0, response=resp)
Пример #3
0
def thread_details():
    conn = mysql.get_db()
    cursor = conn.cursor()
    if not request.args.get('thread'):
        return jsonify(code=3, response="Wrong request")

    thread_id = request.args.get('thread')
    try:
        cursor.execute("SELECT * FROM Thread WHERE id='%s'" % thread_id)
    except Exception:
        return jsonify(code=3, response="Wrong request")

    thread = cursor.fetchall()
    if not thread:
        return jsonify(code=3, response="No such thread")
    thread_info = thread[0]

    forum_info = thread_info[1]
    user_info = thread_info[4]
    related_list = request.args.getlist('related')

    for related in related_list:
        if related == 'user':
            user_info = get_user_info_external(cursor, thread_info[4])
        elif related == 'forum':
            forum_info = get_forum_info_external(cursor, thread_info[1])
        elif related == 'thread':
            return jsonify(code=3, response="Wrong request")

    num_posts = count_posts_in_thread(cursor, thread_id)
    if true_false_ret(thread_info[8]):
        num_posts = 0

    resp = {
        "id": thread_info[0],
        "forum": forum_info,
        "title": thread_info[2],
        "isClosed": true_false_ret(thread_info[3]),
        "user": user_info,
        "date": datetime.datetime.strftime(thread_info[5], "%Y-%m-%d %H:%M:%S"),
        "message": thread_info[6],
        "slug": thread_info[7],
        "isDeleted": true_false_ret(thread_info[8]),
        "likes": thread_info[9],
        "dislikes": thread_info[10],
        "points": thread_info[11],
        "posts": num_posts
    }
    return jsonify(code=0, response=resp)
Пример #4
0
def post_details():
    conn = mysql.get_db()
    cursor = conn.cursor()
    post_id = request.args.get('post')
    if not post_id:
        return jsonify(code=3, response="Wrong request")
    if int(post_id) < 0:
        cursor.execute("SELECT max(id) FROM Post")
        info = cursor.fetchall()
        if info:
            post_id = int(info[0][0]) + int(post_id) + 1
    try:
        cursor.execute("SELECT * FROM Post WHERE id='%s'" % post_id)
    except Exception:
        return jsonify(code=3, response="Wrong request")
    post = cursor.fetchall()
    if not post:
        return jsonify(code=1, response="User doesn't exist")
    post_info = post[0]
    thread_info = post_info[2]
    user_info = post_info[4]
    forum_info = post_info[5]
    related = request.args.getlist('related')
    if 'user' in related:
        user_info = get_user_info_external(cursor, post_info[4])
    if 'forum' in related:
        forum_info = get_forum_info_external(cursor, post_info[5])
    if 'thread' in related:
        thread_info = get_thread_info_external(cursor, post_info[2])

    resp = {
        "date": datetime.datetime.strftime(post_info[1], "%Y-%m-%d %H:%M:%S"),
        "dislikes": post_info[13],
        "forum": forum_info,
        "id": post_info[0],
        "isApproved": true_false_ret(post_info[7]),
        "isDeleted": true_false_ret(post_info[11]),
        "isEdited": true_false_ret(post_info[9]),
        "isHighlighted": true_false_ret(post_info[8]),
        "isSpam": true_false_ret(post_info[10]),
        "likes": post_info[12],
        "message": post_info[3],
        "parent": zero_check(post_info[6]),
        "points": post_info[14],
        "thread": thread_info,
        "user": user_info
    }
    return jsonify(code=0, response=resp)
Пример #5
0
def post_details():
    conn = mysql.get_db()
    cursor = conn.cursor()
    post_id = request.args.get('post')
    if not post_id:
        return jsonify(code=3, response="Wrong request")
    if int(post_id) < 0:
        cursor.execute("SELECT max(id) FROM Post")
        info = cursor.fetchall()
        if info:
            post_id = int(info[0][0]) + int(post_id) + 1
    try:
        cursor.execute("SELECT * FROM Post WHERE id='%s'" % post_id)
    except Exception:
         return jsonify(code=3, response="Wrong request")
    post = cursor.fetchall()
    if not post:
        return jsonify(code=1, response="User doesn't exist")
    post_info = post[0]
    thread_info = post_info[2]
    user_info = post_info[4]
    forum_info = post_info[5]
    related = request.args.getlist('related')
    if 'user' in related:
        user_info = get_user_info_external(cursor, post_info[4])
    if 'forum' in related:
        forum_info = get_forum_info_external(cursor, post_info[5])
    if 'thread' in related:
        thread_info = get_thread_info_external(cursor, post_info[2])

    resp = {
        "date": datetime.datetime.strftime(post_info[1], "%Y-%m-%d %H:%M:%S"),
        "dislikes": post_info[13],
        "forum": forum_info,
        "id": post_info[0],
        "isApproved": true_false_ret(post_info[7]),
        "isDeleted": true_false_ret(post_info[11]),
        "isEdited": true_false_ret(post_info[9]),
        "isHighlighted": true_false_ret(post_info[8]),
        "isSpam": true_false_ret(post_info[10]),
        "likes": post_info[12],
        "message": post_info[3],
        "parent": zero_check(post_info[6]),
        "points": post_info[14],
        "thread": thread_info,
        "user": user_info
    }
    return jsonify(code=0, response=resp)