Beispiel #1
0
def profile_person(uid):
    read_from_xapian = 0
    sharding = False
    timerange = request.args.get('during_time', None)
    if not timerange:
        timerange = default_timerange
    else:
        timerange = timerange.strip()

    start_ts, end_ts = _time_zone(_utf_encode(timerange))

    if 'logged_in' in session and session['logged_in']:
        if session['user'] == 'admin':
            if uid:
                user = {}

                _active, _important, _reposts, _original, _emoticon, _direct_interact, _retweeted_interact, _keywords_dict = getPersonData(uid, default_profile_person_time)
                user['updatetime'] = default_profile_person_time
                user['active_rank'] = _active
                user['important_rank'] = _important

                if read_from_xapian:
                    count, get_results = xapian_search_user.search(query={'_id': int(uid)}, fields=['profile_image_url', 'name', 'friends_count', \
                                                      'statuses_count', 'followers_count', 'gender', 'verified', 'created_at', 'location'])
                    if count > 0:
                        for r in get_results():
                            user_character = {'id': uid, 'profile_image_url': r['profile_image_url'], 'userName':  _utf_8_decode(r['name']), 'friends_count': r['friends_count'], \
                                    'statuses_count': r['statuses_count'], 'followers_count': r['followers_count'], 'gender': r['gender'], \
                                    'verified': r['verified'], 'created_at': r['created_at'], 'location': _utf_8_decode(r['location'])}
                            user.update(user_character)
                            user['created_at'] = ts2HMS(user['created_at']);
                            
                    else:
                        return 'no such user'

                else:
                    status1, personbasic = _search_person_basic(uid, sharding)

                    if status1 == 'success':
                        verifiedTypenum = personbasic.verifiedType
                        friendsCount = personbasic.friendsCount
                        followersCount = personbasic.followersCount
                        statuseCount = personbasic.statuseCount
                        created_at = time.strftime("%m月 %d日, %Y", time.localtime(personbasic.created_at))
                        user_character = {'id': personbasic.userId, 'profile_image_url': personbasic.profileImageUrl, 'userName':  _utf_8_decode(personbasic.name), \
                                'friends_count': friendsCount, 'statuses_count': statuseCount, 'followers_count': followersCount, \
                                'gender': personbasic.gender, 'verified': personbasic.verified, 'created_at': _utf_8_decode(created_at), \
                                'location': _utf_8_decode(personbasic.location), 'date': personbasic.date, \
                                'verifiedTypenum': verifiedTypenum, 'description': _utf_8_decode(personbasic.description)}
                        user.update(user_character)
                    else:
                        return 'no such user'

                return render_template('profile/profile_person.html', user=user, start_ts=start_ts, end_ts=end_ts, timerange=timerange)
            else:
                return redirect('/')
    else:
        return redirect('/')
Beispiel #2
0
    def _to_dict(self):
        person_dict = {}
        person_dict['statuses_count'] = self.statuseCount
        person_dict['followers_count'] = self.followersCount
        person_dict['friends_count'] = self.friendsCount
        person_dict['name'] = self.name
        person_dict['description'] = self.description
        person_dict['profile_image_url'] = self.profileImageUrl
        person_dict['_id'] = self.userId
        person_dict['location'] = self.location
        person_dict['gender'] = u'男' if self.gender == 'm' else u'女'
        person_dict['verifiedType'] = self.verifiedType
        person_dict['verified'] = u'是' if self.verified else u'否'
        person_dict['created_at'] = ts2HMS(self.created_at)
        person_dict['domain'] = self.domain

        return person_dict
Beispiel #3
0
def thumbnail_user_info(uid):
    user = {}
    item = xapian_search_user.search_by_id(int(uid), fields=thumbnail_user_fields)
    if item:
	for f in thumbnail_user_fields:
            if f == 'verified':
		user[f] = u'是' if item[f] == True else u'否'
	    elif f == 'created_at':
	        try:
		    user[f] = ts2HMS(item[f])
		except:
		    user[f] = ''
	    elif f == 'gender':
	        if item[f] == 'f':
                    user[f] = u'女'
                elif item[f] == 'm':
                    user[f] = u'男'
                else:
                    user[f] = u'未知'
            else:
                user[f] = item[f]
		
    return user
Beispiel #4
0
def _multi_search(query_dict, sort, top_n=1000, sharding=True):
    pros = []
    if sort == 'followers_count':
        sort = 'followersCount'
    elif sort == 'statuses_count':
        sort = 'statuseCount'
    elif sort == 'friends_count':
        sort = 'friendsCount'
    elif sort == 'created_at':
        sort = 'created_at'

    if '$and' in query_dict:
        and_querys = query_dict['$and']
        for q in and_querys:
            if 'statuses_count' in q:
                s_low = q['statuses_count']['$gt']
                s_up = q['statuses_count']['$lt']

            if 'followers_count' in q:
                fol_low = q['followers_count']['$gt']
                fol_up = q['followers_count']['$lt']

            if 'friends_count' in q:
                fri_low = q['friends_count']['$gt']
                fri_up = q['friends_count']['$lt']

            if '$or' in q:
                or_querys = q['$or']
                for _q in or_querys:
                    pro = _q['location']
                    if pro != '':
                        pros.append(pro)        

    if sharding:
        cobar_conn = MySQLdb.connect(host=COBAR_HOST, user=COBAR_USER, db='cobar_db_weibo', port=COBAR_PORT, charset='utf8')
    else:
        cobar_conn = MySQLdb.connect(host=MYSQL_HOST, user=MYSQL_USER, db=MYSQL_DB, charset='utf8')

    persons = []
    cursor = cobar_conn.cursor()
    location_query = ""

    if len(pros):
        location_query += "and ("
        for iter_count, pro in enumerate(pros):
            if iter_count != len(pros) - 1:
                location_query += "location like '%s' OR " % (pro)
            else:
                location_query += "location like '%s'" % (pro)                
        location_query += ") "

    sql = "SELECT * from profile_person_basic where statuseCount > %d  and statuseCount < %d and followersCount > %d and \
          followersCount < %d and friendsCount > %d and friendsCount < %d " % (s_low, \
          s_up, fol_low, fol_up, fri_low, fri_up) + location_query + "ORDER BY %s DESC LIMIT %d" % (sort, top_n) # followersCount, top_n

    try:
        cursor.execute(sql)
        results = cursor.fetchall()
    except:
        return persons

    for person in results:
        person_dict = {}
        _id, userId, province, city, verified, name, gender, profileImageUrl, verifiedType, friendsCount, followersCount, statuseCount, location, description, created_at, domain, date = person
        person_dict['statuses_count'] = statuseCount
        person_dict['followers_count'] = followersCount
        person_dict['friends_count'] = friendsCount
        person_dict['name'] = name
        person_dict['description'] = description
        person_dict['profile_image_url'] = profileImageUrl
        person_dict['_id'] = userId
        person_dict['location'] = location
        if gender == 'f':
            person_dict['gender'] = u'女'
        elif gender == 'm':
            person_dict['gender'] = u'男'
        else:
            person_dict['gender'] = u'未知'
        person_dict['verifiedType'] = verifiedType
        person_dict['verified'] = u'是' if verified else u'否'
        person_dict['created_at'] = ts2HMS(created_at)
        person_dict['domain'] = domain
        persons.append(person_dict)

    cobar_conn.close() 

    return persons
Beispiel #5
0
        person_dict['followers_count'] = followersCount
        person_dict['friends_count'] = friendsCount
        person_dict['name'] = name
        person_dict['description'] = description
        person_dict['profile_image_url'] = profileImageUrl
        person_dict['_id'] = userId
        person_dict['location'] = location
        if gender == 'f':
            person_dict['gender'] = u'女'
        elif gender == 'm':
            person_dict['gender'] = u'男'
        else:
            person_dict['gender'] = u'未知'
        person_dict['verifiedType'] = verifiedType
        person_dict['verified'] = u'是' if verified else u'否'
        person_dict['created_at'] = ts2HMS(created_at)
        person_dict['domain'] = domain
        persons.append(person_dict)

    cobar_conn.close() 

    return persons


def _search_by_domain(domain, limit=1000, sharding=True):
    if sharding:
        cobar_conn = MySQLdb.connect(host=COBAR_HOST, user=COBAR_USER, db='cobar_db_weibo', port=COBAR_PORT, charset='utf8')
        print 'sharding'
    else:
        cobar_conn = MySQLdb.connect(host=MSYQL_HOST, user=MYSQL_USER, db=MYSQL_DB, charset='utf8')
        print 'single node'