def thread_details(): try: thread = request.args['thread'] related = request.args.getlist('related') if not all(i in ('user', 'forum') for i in related): raise InvalidArg return jsonify(code=0, response=get_thread_info(thread, db, related)) except KeyError: return jsonify(code=2, response='invalid json') except DoesNotExist: return jsonify(code=1, response='does not exist') except IntegrityError, e: return jsonify(code=2, response='something not found')
def thread_update(): cursor = db.get_cursor() try: data = request.get_json() message = data['message'] slug = data['slug'] thread = data['thread'] cursor.execute("update threads set message = %s, slug = %s where id = %s",(message, slug, thread)) db.commit() cursor.close() return jsonify(code=0, response=get_thread_info(thread, db)) except KeyError: return jsonify(code=2, response='invalid json') except IntegrityError: return jsonify(code=1, response='not found') except: return jsonify(code=4, response='opps')
def forum_listPosts(): cursor = db.get_cursor(MySQLdb.cursors.DictCursor) try: forum = request.args['forum'] limit = request.args.get('limit', '') order = request.args.get('order', 'desc') since_date = request.args.get('since', False) related = request.args.getlist('related') query = "" query_params = () if since_date: query = "select * from posts where forum = %s and date >= %s order by date " + order query_params += ( forum, since_date, ) else: query = "select * from posts where forum = %s order by date " + order query_params += (forum, ) if limit != '': query += " limit " + limit cursor.execute(query, query_params) posts = cursor.fetchall() for post in posts: if 'user' in related: post.update({'user': get_user_info(post['user'], db)}) if 'thread' in related: post.update({'thread': get_thread_info(post['thread'], db)}) if 'forum' in related: post.update({'forum': get_forum_info(post['forum'], db)}) post.update({"date": str(post["date"])}) cursor.close() return jsonify(code=0, response=posts) except DoesNotExist: return jsonify(code=1, response='does not exist') except IntegrityError, e: return jsonify(code=1, response='something not found')
def thread_update(): cursor = db.get_cursor() try: data = request.get_json() message = data['message'] slug = data['slug'] thread = data['thread'] cursor.execute( "update threads set message = %s, slug = %s where id = %s", (message, slug, thread)) db.commit() cursor.close() return jsonify(code=0, response=get_thread_info(thread, db)) except KeyError: return jsonify(code=2, response='invalid json') except IntegrityError: return jsonify(code=1, response='not found') except: return jsonify(code=4, response='opps')
def forum_listPosts(): cursor = db.get_cursor(MySQLdb.cursors.DictCursor) try: forum = request.args['forum'] limit = request.args.get('limit', '') order = request.args.get('order', 'desc') since_date = request.args.get('since', False) related = request.args.getlist('related') query = "" query_params = () if since_date: query = "select * from posts where forum = %s and date >= %s order by date " + order query_params += (forum, since_date, ) else: query = "select * from posts where forum = %s order by date " + order query_params += (forum,) if limit != '': query += " limit " + limit cursor.execute(query, query_params) posts = cursor.fetchall() for post in posts: if 'user' in related: post.update({'user': get_user_info(post['user'], db)}) if 'thread' in related: post.update({'thread': get_thread_info(post['thread'], db)}) if 'forum' in related: post.update({'forum': get_forum_info(post['forum'], db)}) post.update({"date": str(post["date"])}) cursor.close() return jsonify(code=0, response=posts) except DoesNotExist: return jsonify(code=1, response='does not exist') except IntegrityError, e: return jsonify(code=1, response='something not found')
def thread_vote(): cursor = db.get_cursor() try: data = request.get_json() vote = data['vote'] thread = data['thread'] if vote == 1: cursor.execute("update threads set likes = likes + 1, points = points + 1 where id = %s",(thread,)) else: cursor.execute("update threads set dislikes = dislikes + 1, points = points - 1 where id = %s",(thread,)) db.commit() cursor.close() return jsonify(code=0, response=get_thread_info(thread, db)) except KeyError: return jsonify(code=2, response='invalid json') except IntegrityError: return jsonify(code=1, response='not found') except: return jsonify(code=4, response='opps')
def thread_vote(): cursor = db.get_cursor() try: data = request.get_json() vote = data['vote'] thread = data['thread'] if vote == 1: cursor.execute( "update threads set likes = likes + 1, points = points + 1 where id = %s", (thread, )) else: cursor.execute( "update threads set dislikes = dislikes + 1, points = points - 1 where id = %s", (thread, )) db.commit() cursor.close() return jsonify(code=0, response=get_thread_info(thread, db)) except KeyError: return jsonify(code=2, response='invalid json') except IntegrityError: return jsonify(code=1, response='not found') except: return jsonify(code=4, response='opps')
def index(): get_thread_info(63, db) return "lol"