示例#1
0
def getUserInfo(request, username):
    current_user = request.user
    is_authenticated = request.user.is_authenticated()
    channelName = '#' + 'web'
    # This user does not exist in the database
    if (models.hasUserSpoken(username) == False):
        #render a 'cannot find user' page
        return render(request, 'stats/nouser.html', locals())

    username = models.getNormalizedUserName(username)
    mostFullTime = __getMostFullTime(channelName)
    firstAndLastSeenConvo = models.getFirstAndLastSeen(channelName, username)
    firstSeen = firstAndLastSeenConvo[0]
    lastSeen = firstAndLastSeenConvo[1]
    isUserOnline = models.isUserOnline(username)
    userMessageCountOverall = '{0:,}'.format(models.userMessageCountOverall(channelName, username))
    fiddles = models.getLatestFiddles(channelName, username)

    # Get the last time the user was seen
    notSeenFor = {}
    notSeenFor['days'] = models.lastSeenDelta(channelName, username).days
    notSeenFor['seconds'] = models.lastSeenDelta(channelName, username).seconds
    notSeenFor['hours'] = notSeenFor['seconds'] // 3600
    notSeenFor['seconds'] = notSeenFor['seconds'] - (notSeenFor['hours'] * 3600)
    notSeenFor['minutes'] = notSeenFor['seconds'] // 60
    notSeenFor['seconds'] = (notSeenFor['minutes'] * 60)

    avgPostsPerDay = models.avgPerDay('#web', username)
    return render(request, 'stats/userinfo.html', locals())
示例#2
0
def userInfo(request, userName):
    data = {}
    if models.getNormalizedUserName(userName):
        data['username'] = userName = models.getNormalizedUserName(userName)
        data['isUserOnline'] = models.isUserOnline(userName)
        data['karma'] = models.getKarma(userName)['karma__sum']
        # Get the last time the user was seen
        notSeenFor = {}
        notSeenFor['days'] = models.lastSeenDelta('#web', userName).days
        notSeenFor['seconds'] = models.lastSeenDelta('#web', userName).seconds
        notSeenFor['hours'] = notSeenFor['seconds'] // 3600
        notSeenFor['seconds'] = notSeenFor['seconds'] - (notSeenFor['hours'] * 3600)
        notSeenFor['minutes'] = notSeenFor['seconds'] // 60
        notSeenFor['seconds'] = (notSeenFor['minutes'] * 60)
        data['userNotSeenFor'] = notSeenFor

        #  get JS fiddles if user has any
        data['fiddles'] = models.getLatestFiddles('#web', userName)
        if (data['fiddles']):
            for fiddle in data['fiddles']:
                fiddle['timestamp'] = str(fiddle['timestamp'])
                del fiddle['user']

        #  Get last seen and first seem
        lastSeen = models.getUserLastSeen('#web', userName)
        data['lastSeen'] = {}
        data['lastSeen']['message'] = lastSeen.content
        data['lastSeen']['timeStamp'] = str(lastSeen.timestamp)
        data['lastSeen']['messageID'] = lastSeen.id

        firstSeen = models.getUserFirstSeen('#web', userName)
        data['firstSeen'] = {}
        data['firstSeen']['message'] = firstSeen.content
        data['firstSeen']['timestamp'] = str(firstSeen.timestamp)
        data['firstSeen']['messageID'] = firstSeen.id

        # Message count
        data['messageCount'] = models.userMessageCountOverall('#web', userName)
        data['avgPostsPerDay'] = models.avgPerDay('#web', userName)

        return HttpResponse(json.dumps(data), content_type="application/json")

    else:
        return HttpResponse(json.dumps({'statusCode': '404', 'response':'Sorry no available user: ' + userName}), status=404)