示例#1
0
def own_fans_filter(request):
    page = 1
    tags = ''
    if request.GET.has_key('tags'):
        tags = request.GET['tags']
    if request.GET.has_key('page'):
        page = int(request.GET['page'])
    
    tag_1 = tags.split(',')
    user_list = []
    
    #connect to the mysql db
    conn = mysqlconn.dbconn()
    cursor = conn.cursor()
    
    #get all fans
    sql = 'select * from user;'
    cursor.execute(sql)
    fans = cursor.fetchall()
    
    for fan in fans:
        user_dict = dict(id=fan[0], screenname=fan[1], sex=fan[2], address=fan[3], description=fan[4], followersnumber=fan[5],fansnumber=fan[6],messagesnumber=fan[7],birthday=fan[9],matchcount = 0,tag=[],tagstring='')
        cursor.execute('select tag from user_tag where uid ='+fan[0])
        tags = cursor.fetchall()
        for tag in tags:
            user_dict['tag'].append(tag[0])
        user_list.append(user_dict)
    for user in user_list:
        for tag in user['tag']:
            user['tagstring'] = user['tagstring'] + tag+' '
            for tag_target in tag_1:
                if tag.find(tag_target)!=-1:
                    user['matchcount']=user['matchcount']+1
    user_list.sort(lambda p1,p2:cmp(p1['matchcount'],p2['matchcount']),reverse=True)
    #未来在这里添加分页
    
    #close the cursor
    cursor.close()
    #disconnet the link to mysql db
    mysqlconn.dbclose(conn)
    
    return render_to_response('own_fans_filter.html', {'fans':user_list[0:9]})
示例#2
0
def management_fans(request):
    p = 0
    type = 'null'
    if request.GET.has_key('p'):
        p = request.GET['p']
    if request.GET.has_key('type'):
        type = request.GET['type']
    #connect to the mysql
    conn = mysqlconn.dbconn()
    cursor = conn.cursor()
    sql = 'select user.screenname, user.sex, user.address, user.fansnumber, user.id from user, user_vector where user.id = user_vector.uid order by '+type+' desc limit '+str(int(p)*20)+',20;'
    cursor.execute(sql)
    fans = cursor.fetchall()
    print fans

    #close the cursor
    cursor.close()
    #disconnet the link to mysql db
    mysqlconn.dbclose(conn)
    

    return render_to_response('management_fans.html', {'fans':fans, 'page':int(p), 'type':type})
示例#3
0
import client
import mysqlconn

if __name__ == '__main__':
    #connect to the mysql db
    conn = mysqlconn.dbconn()

    Client = client.Client.instance()
    if Client._init == 0:
        Client.init()
    ids = Client.get_friendids('1710173801').ids

    try:
        for id in ids:
            cursor = conn.cursor()
            insertstring = 'insert ignore into oppo_follow (uid,follow_id) values ( \'1710173801\',' + '\'' + str(
                id) + '\'' + ')'
            cursor.execute(insertstring)
            #close the cursor
            cursor.close()
            conn.commit()

    except Exception:
        pass

    #disconnet the link to mysql db
    mysqlconn.dbclose(conn)
示例#4
0
# -*- coding: UTF-8 -*- 
# Create your views here.


import weiboconfig as config
import client
import mysqlconn

if __name__=='__main__':
    #connect to the mysql db
    conn = mysqlconn.dbconn()
   
    
    Client = client.Client.instance()
    if Client._init ==0:
       Client.init()
    statuses_count = Client.get_statuses_user_timeline('1710173801').total_number;
    count = 100
    page_count =  statuses_count/count+1
    print page_count
    for i in range(1, page_count+1):   
        statuses = Client.get_statuses_user_timeline('1710173801',count,i).statuses
        for status in statuses:
            try:
                cursor = conn.cursor()
                insertstring = 'insert ignore into oppo_weibo (mid,text,source,reposts_count,comments_count,attitudes_count,id,created_at) values ('+'\''+str(status.mid)+'\''+','+'\''+status.text+'\''+','+'\''+status.source+'\''+','+str(status.reposts_count)+','+str(status.comments_count)+','+str(status.attitudes_count)+','+'\''+str(status.id)+'\''+','+'\''+status.created_at+'\''+')'
                cursor.execute(insertstring)
                #close the cursor
                cursor.close()
                conn.commit()
            except Exception:
示例#5
0
def status_fans(request):
    #connect to the mysql db
    conn = mysqlconn.dbconn()
    cursor = conn.cursor()

    #get sum of the fans
    sql = 'select count(*) from user;'
    cursor.execute(sql)
    sum = cursor.fetchone()[0]
    #get the female num
    sql = 'select count(*) from user where sex="f";'
    cursor.execute(sql)
    fnum = cursor.fetchone()[0]
    #the percentage of female
    fperc = round(fnum / sum, 4) * 100
    mperc = round((sum - fnum) / sum, 4) * 100
   
    #get the top10 area
    sql = 'select address, count(*) as num from user where address <> "其他" group by address order by num desc limit 0,10;'
    cursor.execute(sql)
    areadic = cursor.fetchall()
    areaname = []
    areanum = []
    for area in areadic:
        areaname.append(area[0].encode('utf8'))
        areanum.append(int(area[1]))

    thisyear = time.strftime('%Y',time.localtime(time.time())) #this year, like '2012'
    #get the num of each age interval
    sql = 'select count(*) from user where birthday > ' + thisyear + '-18;'
    cursor.execute(sql)
    age1 = cursor.fetchone()[0]
    sql = 'select count(*) from user where birthday <= ' + thisyear + '-18 and birthday >= ' + thisyear + '-24;'
    cursor.execute(sql)
    age2 = cursor.fetchone()[0]
    sql = 'select count(*) from user where birthday < ' + thisyear + '-24 and birthday >= ' + thisyear + '-34;'
    cursor.execute(sql)
    age3 = cursor.fetchone()[0]
    sql = 'select count(*) from user where birthday < ' + thisyear + '-34;'
    cursor.execute(sql)
    age4 = cursor.fetchone()[0]
    sum = age1 + age2 + age3 + age4
    age = []
    age.append(round(age1 / sum, 4) * 100)
    age.append(round(age2 / sum, 4) * 100)
    age.append(round(age3 / sum, 4) * 100)
    age.append(round(age4 / sum, 4) * 100)

    #get the last weibo sent from where
    sql = 'select count(*) from user_source;'
    cursor.execute(sql)
    sum = cursor.fetchone()[0]
    sql = 'select source, count(*) as num from user_source group by source order by num desc limit 12;'
    cursor.execute(sql)
    sentfrom = []
    for source, num in cursor.fetchall():
        sentfrom.append((source, round(num / sum, 4) * 100))

    #the distribution of the fans' tag
    sql = 'select count(*) from user_tag;'
    cursor.execute(sql)
    sum = cursor.fetchone()[0]
    sql = 'select tag, count(*) as num from user_tag group by tag order by num desc limit 10;'
    cursor.execute(sql)
    tagdic = cursor.fetchall()
    tag = []
    for t in tagdic:
        tag.append((t[0].encode('utf8'), round(t[1] / sum, 4) * 100))

    #close the cursor
    cursor.close()
    #disconnet the link to mysql db
    mysqlconn.dbclose(conn)


    return render_to_response('status.html', {'male':mperc, 'female':fperc, 'areaname':areaname, 'areanum':areanum, 'age':age, 'source':sentfrom, 'tag':tag})