Exemplo n.º 1
0
def retrieveFollowMeList(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data

    userId = int(userId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '关注获取失败'}
        return data
    result = followDao.selectFollowMeList(userId, x, n)
    if result is None:
        data = {'code': 1, 'msg': '请先登录'}
    else:
        data = []
        total = followDao.selectSumFollowByFollowId(userId)
        for followMe in result:
            followMeId = followMe.userId
            userData = usersDao.selectUserByUserId(int(followMeId))
            fol = {
                'followMeId ': followMeId,
                'username': userData['username'],
                'iconUrl': userData['iconUrl']
            }
            data.append(fol)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Exemplo n.º 2
0
def retrieveUserBySessionId(session_id):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    try:
        userId = redisCon.get(session_id)
        result = usersDao.selectUserByUserId(userId)
    except Exception:
        data = {'code': 1, 'msg': '用户信息获取失败'}
        return data
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    if result is None:
        data = {'code': 1, 'msg': '用户信息获取失败'}
    else:
        data = {
            'code': 0,
            'tel': result['tel'],
            'username': result['username'],
            'gender': result['gender'],
            'age': result['age'],
            'height': result['height'],
            'weight': result['weight'],
            'area': result['area'],
            'job': result['job'],
            'iconUrl': result['iconUrl'],
            'integral': result['integral']
        }
    return data
Exemplo n.º 3
0
def adminGetFromXGetNTopic(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    result = topicDao.selectFromXGetNTopic(x, n)
    if result is None:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    else:
        data = []
        total = topicDao.selectSumTopic()
        for topic in result:
            topicId = topic.topicId
            userId = topic.userId
            lastTime = topic.lastTime.strftime('%Y-%m-%d %H:%M:%S')
            content = topic.content[:40]
            picture1 = topic.picture1
            picture2 = topic.picture2
            picture3 = topic.picture3
            replyNum = topic.replyNum
            comNum = topic.comNum
            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '话题获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']

            top = {'topicId': topicId,
                   'userId': userId,
                   'username': username,
                   'iconUrl': iconUrl,
                   'lastTime': lastTime,
                   'content': content,
                   'picture1': picture1,
                   'picture2': picture2,
                   'picture3': picture3,
                   'replyNum': replyNum,
                   'comNum': comNum}
            data.append(top)
        data = {'code': 0, 'rows': data, 'total': total}
    return data
Exemplo n.º 4
0
def retrieveLastTopicList(session_id, topicIdList, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if topicIdList == '':
        data = {'code': 1, 'msg': '已有话题列表不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    n = int(n)
    if n <= 0:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    topicIdList = eval(topicIdList)
    result = topicDao.selectLastTopicList(topicIdList, n)
    if result is None:
        data = {'code': 1, 'msg': '话题获取失败'}
        return data
    else:
        data = []
        for topic in result:
            topicId = topic.topicId
            userId = topic.userId
            lastTime = topic.lastTime.strftime('%Y-%m-%d %H:%M:%S')
            content = topic.content[:40]
            picture1 = topic.picture1
            picture2 = topic.picture2
            picture3 = topic.picture3
            replyNum = topic.replyNum
            comNum = topic.comNum
            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '话题获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']

            top = {'topicId': topicId,
                   'userId': userId,
                   'username': username,
                   'iconUrl': iconUrl,
                   'lastTime': lastTime,
                   'content': content,
                   'picture1': picture1,
                   'picture2': picture2,
                   'picture3': picture3,
                   'replyNum': replyNum,
                   'comNum': comNum}
            data.append(top)
        data = {'code': 0, 'data': data}
    return data
Exemplo n.º 5
0
def retrieveSubReplyFromXGetN(session_id, replyId, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if replyId == '':
        data = {'code': 1, 'msg': '跟帖ID不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    replyId = int(replyId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '跟帖评论获取失败'}
        return data
    result = subReplyDao.selectSubReplyFromXGetN(replyId, x, n)
    if result is None:
        data = {'code': 1, 'msg': '跟帖评论获取失败'}
        return data
    else:
        data = []
        total = subReplyDao.selectSumSubReplyByReplyId(replyId)
        for subreply in result:
            subreplyId = subreply.subreplyId
            userId = subreply.userId
            subreplyTime = subreply.subreplyTime.strftime('%Y-%m-%d %H:%M:%S')
            content = subreply.content
            likes = subreply.likes

            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '跟帖评论获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']

            subrep = {
                'subreplyId': subreplyId,
                'userId': userId,
                'iconUrl': iconUrl,
                'username': username,
                'content': content,
                'subreplyTime': subreplyTime,
                'likes': likes
            }
            data.append(subrep)
        data = {'code': 0, 'data': data}
    return data
Exemplo n.º 6
0
def retrieveFavoriteTopic(session_id, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    userId = int(userId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '获取收藏的话题失败'}
        return data
    favoriteData = favoriteTopicDao.seletcUserFavoriteTopic(userId, x, n)
    if favoriteData is None:
        data = {'code': 1, 'msg': '获取收藏的话题失败'}
    else:
        data = []
        total = favoriteTopicDao.selectSumFavoriteTopicByUserId(userId)
        for favorite in favoriteData:
            topicId = favorite.topicId
            topic = topicDao.selectTopicByTopicId(topicId)
            user = usersDao.selectUserByUserId(userId)
            if topic is None or user is None:
                data = {'code': 1, 'msg': '获取收藏的话题失败'}
                return data

            content = topic.content[:40]
            picture1 = topic.picture1
            picture2 = topic.picture2
            picture3 = topic.picture3
            iconUrl = user['iconUrl']
            username = user['username']

            data.append({
                'topicId': topicId,
                'content': content,
                'picture1': picture1,
                'picture2': picture2,
                'picture3': picture3,
                'userId': userId,
                'iconUrl': iconUrl,
                'username': username
            })
        data = {'code': 0, 'data': data, 'total': total}
    return data
Exemplo n.º 7
0
def getFromXGetNCommentByArticleId(session_id, articleId, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if articleId == '':
        data = {'code': 1, 'msg': 'articleId不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    articleId = int(articleId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '评论获取失败'}
        return data
    result = commentDao.selectFromXGetNCommentByArticleId(articleId, x, n)
    if result is None:
        data = {'code': 1, 'msg': '无法获取x之后n个评论'}
    else:
        data = []
        total = commentDao.selectSumCommentByArticleId(articleId)
        for comment in result:
            commentId = comment.commentId
            content = comment.content
            commentTime = comment.commentTime.strftime('%Y-%m-%d %H:%M:%S')
            userId = comment.userId
            likes = comment.likes
            userData = usersDao.selectUserByUserId(userId)
            username = userData['username']
            iconUrl = userData['iconUrl']

            art = {'commentId': commentId,
                   'content': content,
                   'commentTime': commentTime,
                   'userId': userId,
                   'likes': likes,
                   'username': username,
                   'iconUrl': iconUrl
                   }
            data.append(art)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Exemplo n.º 8
0
def retrieveTopicLikeTopic(session_id, keyword, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if keyword == '':
        data = {'code': 1, 'msg': '关键词不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': '起始位置不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': '文章数量不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    x = int(x)
    n = int(n)
    if n <= 0 or x < 0:
        data = {'code': 1, 'msg': '搜索失败'}
        return data
    result = topicDao.selectTopicLikeContent(keyword, x, n)
    if result is None:
        data = {'code': 1, 'msg': '无法搜索文章'}
    else:
        data = []
        total = topicDao.selectSumTopicLikeContent(keyword)
        for topic in result:
            topicId = topic.topicId
            lastTime = topic.lastTime.strftime('%Y-%m-%d %H:%M:%S')
            content = topic.content[:40]
            userId = topic.userId
            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '话题获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']
            top = {'topicId': topicId,
                   'lastTime': lastTime,
                   'content': content,
                   'userId': userId,
                   'username': username,
                   'iconUrl': iconUrl
                   }
            data.append(top)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Exemplo n.º 9
0
def retrieveTopicByTopicId(session_id, topicId):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if topicId == '':
        data = {'code': 1, 'msg': 'topicId不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data

    userId = int(userId)
    topicId = int(topicId)
    topic = topicDao.selectTopicByTopicId(topicId)
    if topic is None:
        data = {'code': 1, 'msg': '获取话题失败'}
    else:
        topicTime = topic.topicTime.strftime('%Y-%m-%d %H:%M:%S')
        likes = topic.likes
        content = topic.content
        picture1 = topic.picture1
        picture2 = topic.picture2
        picture3 = topic.picture3
        picture4 = topic.picture4
        picture5 = topic.picture5
        favorite = favoriteTopicDao.seletcFavoriteTopic(userId, topicId)
        topicUserId = topic.userId
        user = usersDao.selectUserByUserId(topicUserId)
        if user is None:
            data = {'code': 1, 'msg': '话题获取失败'}
            return data
        username = user['username']
        iconUrl = user['iconUrl']
        top = {'userId': topicUserId,
               'username': username,
               'iconUrl': iconUrl,
               'topicTime': topicTime,
               'favorite': favorite,
               'likes': likes,
               'content': content,
               'picture1': picture1,
               'picture2': picture2,
               'picture3': picture3,
               'picture4': picture4,
               'picture5': picture5,
               }
        data = {'code': 0, 'data': top}
    return data
Exemplo n.º 10
0
def retrieveReplyFromXGetN(session_id, topicId, x, n):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if topicId == '':
        data = {'code': 1, 'msg': '话题ID不能为空'}
        return data
    if x == '':
        data = {'code': 1, 'msg': 'x不能为空'}
        return data
    if n == '':
        data = {'code': 1, 'msg': 'n不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    topicId = int(topicId)
    x = int(x)
    n = int(n)
    if x < 0 or n <= 0:
        data = {'code': 1, 'msg': '跟帖获取失败'}
        return data
    result = replyDao.selectReplyFromXGetN(topicId, x, n)
    if result is None:
        data = {'code': 1, 'msg': '跟帖获取失败'}
        return data
    else:
        data = []
        total = replyDao.selectSumReplyByTopicId(topicId)
        for reply in result:
            replyId = reply.replyId
            floor = reply.floor
            userId = reply.userId
            replyTime = reply.replyTime.strftime('%Y-%m-%d %H:%M:%S')
            likes = reply.likes
            comNumber = reply.comNumber
            picture1 = reply.picture1
            picture2 = reply.picture2
            picture3 = reply.picture3
            picture4 = reply.picture4
            picture5 = reply.picture5
            content = reply.content
            user = usersDao.selectUserByUserId(userId)
            if user is None:
                data = {'code': 1, 'msg': '跟帖获取失败'}
                return data
            username = user['username']
            iconUrl = user['iconUrl']

            rep = {
                'replyId': replyId,
                'floor': floor,
                'userId': userId,
                'username': username,
                'iconUrl': iconUrl,
                'replyTime': replyTime,
                'likes': likes,
                'picture1': picture1,
                'picture2': picture2,
                'picture3': picture3,
                'picture4': picture4,
                'picture5': picture5,
                'comNumber': comNumber,
                'content': content
            }
            data.append(rep)
        data = {'code': 0, 'data': data, 'total': total}
    return data
Exemplo n.º 11
0
def retrieveOtherUserInfoByUserId(session_id, otherUserId):
    if session_id == '':
        data = {'code': 1, 'msg': 'session_id不能为空'}
        return data
    if otherUserId == '':
        data = {'code': 1, 'msg': 'otherUserId不能为空'}
        return data
    userId = redisCon.get(session_id)
    if userId is None:
        data = {'code': 1, 'msg': '请先登录'}
        return data
    result = usersDao.selectUserByUserId(otherUserId)
    if result is None:
        data = {'code': 1, 'msg': '用户信息获取失败'}
    else:
        isFollow = followDao.selectFollow(int(userId), int(otherUserId))
        userPrivacy = userPrivacyDao.selectUserPrivacy(int(otherUserId))
        if userPrivacy.isTel == 1:
            tel = result['tel']
        else:
            tel = ''
        if userPrivacy.isGender == 1:
            gender = result['gender']
        else:
            gender = ''
        if userPrivacy.isAge == 1:
            age = result['age']
        else:
            age = ''
        if userPrivacy.isHeight == 1:
            height = result['height']
        else:
            height = ''
        if userPrivacy.isWeight == 1:
            weight = result['weight']
        else:
            weight = ''
        if userPrivacy.isArea == 1:
            area = result['area']
        else:
            area = ''
        if userPrivacy.isJob == 1:
            job = result['job']
        else:
            job = ''
        if userPrivacy.isIntegral == 1:
            integral = result['integral']
        else:
            integral = ''

        data = {
            'code': 0,
            'tel': tel,
            'username': result['username'],
            'gender': gender,
            'age': age,
            'height': height,
            'weight': weight,
            'area': area,
            'job': job,
            'iconUrl': result['iconUrl'],
            'integral': integral,
            'isFollow': isFollow
        }
    return data