Exemplo n.º 1
0
def make_flat_sort_thread(cursor, thread_id, since, limit, order):
    lim = ""
    if limit != 0:
        lim = "LIMIT " + str(limit)
    full_query = "SELECT * " \
                 "FROM Post WHERE thread=%s AND date >= '%s' " \
                 "ORDER BY date %s %s" % (thread_id, since, order, lim)
    cursor.execute(full_query)
    posts_info = cursor.fetchall()
    return flat_sort(cursor, posts_info)
Exemplo n.º 2
0
def make_flat_sort_thread(cursor, thread_id, since, limit, order):
    lim = ""
    if limit != 0:
        lim = "LIMIT " + str(limit)
    full_query = "SELECT * " \
                 "FROM Post WHERE thread=%s AND date >= '%s' " \
                 "ORDER BY date %s %s" % (thread_id, since, order, lim)
    cursor.execute(full_query)
    posts_info = cursor.fetchall()
    return flat_sort(cursor, posts_info)
Exemplo n.º 3
0
def thread_list_posts():
    conn = mysql.get_db()
    cursor = conn.cursor()

    thread_id = request.args.get('thread')
    if not thread_id:
        return jsonify(code=3, response="Wrong request")

    since = request.args.get('since')
    if not since:
        since = "1970-01-01"

    limit = 0
    if request.args.get('limit'):
        limit = int(request.args.get('limit'))

    order_req = request.args.get('order')
    order = "DESC"
    if order_req == "asc":
        order = "ASC"

    sort = request.args.get('sort')
    resp = []
    if sort:

        if sort == 'flat':
            resp = make_flat_sort_thread(cursor, thread_id, since, limit,
                                         order)
        elif sort == 'tree':
            resp = make_tree_sort_thread(cursor, thread_id, since, limit,
                                         order)
        elif sort == 'parent_tree':
            resp = make_parent_tree_sort_thread(cursor, thread_id, since,
                                                limit, order)
    else:
        lim = ""
        if limit != 0:
            lim = "LIMIT " + str(limit)

        full_query = "SELECT * " \
                     "FROM Post WHERE thread=%s AND date >= '%s' " \
                     "ORDER BY date %s %s" % (thread_id, since, order, lim)
        cursor.execute(full_query)
        posts_info = cursor.fetchall()
        if posts_info:
            resp = flat_sort(cursor, posts_info)
        else:
            return jsonify(code=0, response={})

    return jsonify(code=0, response=resp)
Exemplo n.º 4
0
def thread_list_posts():
    conn = mysql.get_db()
    cursor = conn.cursor()

    thread_id = request.args.get('thread')
    if not thread_id:
        return jsonify(code=3, response="Wrong request")

    since = request.args.get('since')
    if not since:
        since = "1970-01-01"

    limit = 0
    if request.args.get('limit'):
        limit = int(request.args.get('limit'))

    order_req = request.args.get('order')
    order = "DESC"
    if order_req == "asc":
        order = "ASC"

    sort = request.args.get('sort')
    resp = []
    if sort:

        if sort == 'flat':
            resp = make_flat_sort_thread(cursor, thread_id, since, limit, order)
        elif sort == 'tree':
            resp = make_tree_sort_thread(cursor, thread_id, since, limit, order)
        elif sort == 'parent_tree':
            resp = make_parent_tree_sort_thread(cursor, thread_id, since, limit, order)
    else:
        lim = ""
        if limit != 0:
            lim = "LIMIT " + str(limit)

        full_query = "SELECT * " \
                     "FROM Post WHERE thread=%s AND date >= '%s' " \
                     "ORDER BY date %s %s" % (thread_id, since, order, lim)
        cursor.execute(full_query)
        posts_info = cursor.fetchall()
        if posts_info:
            resp = flat_sort(cursor, posts_info)
        else:
            return jsonify(code=0, response={})

    return jsonify(code=0, response=resp)