コード例 #1
0
def details():
    con = connect()
    request_data = get_json(request)
    required_data = ["user"]
    try:
        check_data(request_data, required_data)
        user = query.show_user(connect = con, email = request_data["user"])
    except Exception as e:
        con.close()
        return json.dumps({"code" : 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": user})
コード例 #2
0
def unfollow():
    con = connect()
    request_data = get_json(request)
    required_data = ["follower", "followee"]   
    try:
        check_data(request_data, required_data)
        user = query.unfollow_user(con, request_data["follower"], request_data["followee"])
    except Exception as e:
        con.close()        
        return json.dumps({"code" : 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": user })
コード例 #3
0
def list_users():
    con = connect()
    content = get_json(request)
    required_data = ["forum"]    
    optional = intersection(content, ["limit", "order", "since"])    
    try:
        check_data(content, required_data)
        users_l = query.users_list(con, content["forum"], optional)
    except Exception as e:
         con.close()
         return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": users_l})
コード例 #4
0
def list_following():
    con = connect()
    request_data = get_json(request)
    required_data = ["user"]
    followers_param = intersection(request=request_data, values=["limit", "order", "since_id"])
    try:
        check_data(data=request_data, required=required_data)
        follower_l = query.followers_list(connect=con, email=request_data["user"], type="follow", params=followers_param)
    except Exception as e:
        con.close()
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": follower_l})
コード例 #5
0
def user_posts():
    con = connect()
    content = get_json(request)
    required_data = ["user"]
    optional = intersection(content, ["limit", "order", "since"])    
    try:
        check_data(content, required_data)
        posts_l = posts.posts_list(con, "user", optional, content["user"], [])
    except Exception as e:
         con.close()
         return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": posts_l})
コード例 #6
0
def list_threads():
    con = connect()
    content = get_json(request)
    required_data = ["forum"]
    related = related_exists(content)
    optional = intersection(content, ["limit", "order", "since"])
    try:
        check_data(content, required_data)
        threads_l = threads.threads_list(con, "forum", optional, content["forum"], related)
    except Exception as e:
        con.close()
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": threads_l})
コード例 #7
0
def details():
    con = connect()
    content = get_json(request)
    required_data = ["post"]
    related = related_exists(content)
    if 'post' in related:
        con.close()
        return json.dumps({"code": 3, "response": "error"})
    try:
        check_data(content, required_data)
        post = query.show_post(con, content["post"], related)
    except Exception as e:
        con.close()
        return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": post})
コード例 #8
0
def post_list():
    con = connect()
    content = get_json(request)
    try:
        identifier = content["forum"]
        entity = "forum"
    except KeyError:
        try:
            identifier = content["thread"]
            entity = "thread"
        except Exception as e:
            con.close()
            return json.dumps({"code": 1, "response": (e.message)})
    optional = intersection(content, ["limit", "order", "since"])    
    try:
        posts_l = query.posts_list(con, entity, optional, identifier, [])
    except Exception as e:
         con.close()
         return json.dumps({"code": 1, "response": (e.message)})
    con.close()
    return json.dumps({"code": 0, "response": posts_l})