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
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)