Esempio n. 1
0
def get_fans(request):
    access_token=request.session['access_token']
    expires_in=request.session['expires_in']
    client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
    client.set_access_token(access_token, expires_in)
    
    if request.method=="POST":
        form=forms.UserForm(request.POST.copy())
        if form.is_valid():
            username=form.cleaned_data['username']
            user_info=client.users__show(screen_name=username)
            user_id=user_info.id
            #获取用户粉丝
            '''next_cursor=1
            while next_cursor>0:
                fans=client.friendships__followers(screen_name=username,count=200,cursor=next_cursor)
                #fans=client.friendships__followers__active(uid=user_id,count=200)
                next_cursor=fans.next_cursor
                print next_cursor
                for fan in fans.users:
                    userinfo=UserInfo(uname=username,fansid=fan.id,username=fan.screen_name,province=fan.province,city=fan.province,location=fan.location,gender=fan.gender,verified=fan.verified)
                    userinfo.save()'''
                    
            #获取优质粉丝
            user_info=client.users__show(screen_name=username)
            user_id=user_info.id
            active_fans=client.friendships__followers__active(uid=user_id,count=200)
            for active_fan in active_fans.users:
                print active_fan.screen_name
                userinfo=UserInfo(fansid=active_fan.id,username=active_fan.screen_name,province=active_fan.province,city=active_fan.province,location=active_fan.location,gender=active_fan.gender,verified=active_fan.verified)
                userinfo.save()          
    return render_to_response("weibo/operation.html",{'userForm':forms.UserForm()},context_instance=RequestContext(request))