Exemplo n.º 1
0
def listFollowers(isFollowing):
	qs = get_json(request)

	email = qs.get('user')
	if not email:
		return json.dumps({"code": 2, "response": "No 'user' key"}, indent=4)

	# Since part
	since_id = qs.get('since_id', -1)
	if since_id != -1:
		sinceSql = """AND User.user >= {}""".format(since_id)
	else:
		sinceSql = ""

	# Order part
	order_sql = """ORDER BY User.name {}""".format(qs.get('order', 'desc'))

	# Limit part
	limit = qs.get('limit', -1)
	if limit != -1:
		try:
			limit = int(limit)
		except ValueError:
			return json.dumps({"code": 3, "response": "Wrong limit value"}, indent=4)
		if limit < 0:
			return json.dumps({"code": 3, "response": "Wrong limit value"}, indent=4)
		limit_sql = """LIMIT {}""".format(limit)
	else:
		limit_sql = ""

	sql = """SELECT about, email, user, isAnonymous, name, username FROM User JOIN Follower ON """
	if not isFollowing:
		sql += """Follower.follower = User.email WHERE Follower.following"""
	else:
		sql += """Follower.following = User.email WHERE Follower.follower"""

	sql += """ = %(email)s {since_value} {order_value} {limit_value};""".format(
		since_value=sinceSql, order_value=order_sql, limit_value=limit_sql)

	userListSql = db.execute(sql, {'email': email})
	if not userListSql:
		return json.dumps({"code": 1, "response": "Empty set"}, indent=4)

	user_list = list()
	for userSql in userListSql:
		followerEmail = str_to_json(userSql[1])
		user_list.append({'about': str_to_json(userSql[0]),
						  'email': followerEmail,
						  'id': str_to_json(userSql[2]),
						  'isAnonymous': str_to_json(userSql[3]),
						  'name': str_to_json(userSql[4]),
						  'username': str_to_json(userSql[5]),
						  'followers': get_followers_list(followerEmail),
						  'following': get_following_list(followerEmail),
						  'subscriptions': get_subscribed_threads_list(followerEmail)})

	return json.dumps({"code": 0, "response": user_list}, indent=4)
Exemplo n.º 2
0
def details():
	qs = get_json(request)
	email = qs.get('user')
	if not email:
		return json.dumps({"code": 2, "response": "No 'user' key"}, indent=4)

	user = get_user_dict(email)

	user['followers'] = get_followers_list(email)
	user['following'] = get_following_list(email)
	user['subscriptions'] = get_subscribed_threads_list(email)

	return json.dumps({"code": 0, "response": user}, indent=4)
Exemplo n.º 3
0
def details():
    qs = get_json(request)
    email = qs.get('user')
    if not email:
        return json.dumps({"code": 2, "response": "No 'user' key"}, indent=4)

    user = get_user_dict(email)

    user['followers'] = get_followers_list(email)
    user['following'] = get_following_list(email)
    user['subscriptions'] = get_subscribed_threads_list(email)

    return json.dumps({"code": 0, "response": user}, indent=4)
Exemplo n.º 4
0
def listFollowers(isFollowing):
    qs = get_json(request)

    email = qs.get('user')
    if not email:
        return json.dumps({"code": 2, "response": "No 'user' key"}, indent=4)

    # Since part
    since_id = qs.get('since_id', -1)
    if since_id != -1:
        sinceSql = """AND User.user >= {}""".format(since_id)
    else:
        sinceSql = ""

    # Order part
    order_sql = """ORDER BY User.name {}""".format(qs.get('order', 'desc'))

    # Limit part
    limit = qs.get('limit', -1)
    if limit != -1:
        try:
            limit = int(limit)
        except ValueError:
            return json.dumps({
                "code": 3,
                "response": "Wrong limit value"
            },
                              indent=4)
        if limit < 0:
            return json.dumps({
                "code": 3,
                "response": "Wrong limit value"
            },
                              indent=4)
        limit_sql = """LIMIT {}""".format(limit)
    else:
        limit_sql = ""

    sql = """SELECT about, email, user, isAnonymous, name, username FROM User JOIN Follower ON """
    if not isFollowing:
        sql += """Follower.follower = User.email WHERE Follower.following"""
    else:
        sql += """Follower.following = User.email WHERE Follower.follower"""

    sql += """ = %(email)s {since_value} {order_value} {limit_value};""".format(
        since_value=sinceSql, order_value=order_sql, limit_value=limit_sql)

    userListSql = db.execute(sql, {'email': email})
    if not userListSql:
        return json.dumps({"code": 1, "response": "Empty set"}, indent=4)

    user_list = list()
    for userSql in userListSql:
        followerEmail = str_to_json(userSql[1])
        user_list.append({
            'about':
            str_to_json(userSql[0]),
            'email':
            followerEmail,
            'id':
            str_to_json(userSql[2]),
            'isAnonymous':
            str_to_json(userSql[3]),
            'name':
            str_to_json(userSql[4]),
            'username':
            str_to_json(userSql[5]),
            'followers':
            get_followers_list(followerEmail),
            'following':
            get_following_list(followerEmail),
            'subscriptions':
            get_subscribed_threads_list(followerEmail)
        })

    return json.dumps({"code": 0, "response": user_list}, indent=4)