Example #1
0
 def GET(self):
     #获取attentionnotfan.html传过来的数据
     data = web.input()
     on = []
     try:
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
         auth.access_token = session['access_token']
         api = API(auth)
         for x in data:
             on.append(x)
         try:
             #同理,由于有全选按钮.....
             on.remove('checkbox2')
         except:
             pass
         nu = len(on)
         if nu == 0:
             pass
         #取消关注
         map(api.destroy_friendship, on)
         info = "恭喜您已成功取消关注%d位用户....." % nu
         return render_template('success.html', info=info.decode('utf-8'))
     except:
         info = "亲,系统繁忙,请稍后再试......,系统在3秒后自动返回..."
         return render_template('error.html', info=info.decode('utf-8'))
Example #2
0
    def GET(self):
        access_token=session.get('access_token',None)
        if not access_token:
            auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET,web.ctx.get('homedomain')+'/callback')
            auth_url = auth.get_authorization_url()
            session.request_token=auth.request_token
            web.seeother(auth_url)
        else:
            auth =OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
            auth.access_token=access_token
            api=API(auth)
            user=api.verify_credentials()
            user_timeline=user.timeline(count=10)

            print "current user is ",user.screen_name
            hot_list=get_hot_list()
            for user_tweet in user_timeline:
                try:
                    hot_list.append(tuple([user_tweet.user.screen_name,
                                            user_tweet.mid,
                                            user_tweet.text,
                                            user_tweet.source,
                                            user_tweet.created_at,
                                            None,
                                            None]))
                except AttributeError:
                    #no retweet_statues
                    continue
            return render.index(user.screen_name,user.id,hot_list)
Example #3
0
 def GET(self):
     #获取noattentionok.html传过来的数据
     data = web.input()
     on = []
     try:
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
         auth.access_token = session['access_token']
         api = API(auth)
         """ 
         获取noattention.html页面传过来的uid,通过checkbox,由于有一个全选按钮,如果点击,则去掉 
         """
         for x in data:
             on.append(x)
         try:
             on.remove('checkbox2')
         except:
             pass
         nu = len(on)
         if nu == 0:
             pass
         if nu > 60:
             on = on[:60]
             nu = 60
         """ 
         一次最多加60次关注 
         """
         map(api.create_friendship, on)
         info = "恭喜您已成功关注%d位用户....." % nu
         return render_template('success.html', info=info.decode('utf-8'))
     except:
         info = "亲,系统繁忙,请稍后再试......,系统在3秒后自动返回..."
         return render_template('error.html', info=info.decode('utf-8'))
Example #4
0
 def get_auth(self):
     from weibopy.auth import OAuthHandler
     from weibopy.oauth import OAuthToken
     auth = OAuthHandler(settings.SINA_CONSUMER_KEY,
                         settings.SINA_CONSUMER_SECRET)
     auth.access_token = OAuthToken(self.access_token, self.access_secret)
     return auth
Example #5
0
 def analyze(self,query):
     if query=="" or query is None:
         web.seeother("/")
     access_token=session.get('access_token',None)
     auth =OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
     auth.access_token=access_token
     api=API(auth)
     repost_timeline=api.repost_timeline(count=10)
     print repost_timeline
     logging.info("analyzing query %s " % (query))
Example #6
0
    def GET(self):
        try:
            auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
            auth.access_token = session['access_token']
            api = API(auth)
            user = api.verify_credentials()
            fan = []
            next_cursor = -1
            while next_cursor != 0:
                timeline = api.followers(user.id, '', '', '', next_cursor)
                if isinstance(timeline, tuple):
                    next_cursor = timeline[1]
                    for line in timeline[0]:
                        fid = line.__getattribute__("id")
                        fname = line.__getattribute__("screen_name")
                        fan.append((fid, fname))

                else:
                    next_cursor = 0
                    for line in timeline:
                        fid = line.__getattribute__("id")
                        fname = line.__getattribute__("screen_name")
                        fan.append((fid, fname))

            friend = []
            next_cursor = -1
            while next_cursor != 0:
                timeline = api.friends(user.id, '', '', '', next_cursor)
                if isinstance(timeline, tuple):
                    next_cursor = timeline[1]
                    for line in timeline[0]:
                        frid = line.__getattribute__("id")
                        frname = line.__getattribute__("screen_name")
                        friend.append((frid, frname))
                else:
                    next_cursor = 0
                    for line in timeline:
                        frid = line.__getattribute__("id")
                        frname = line.__getattribute__("screen_name")
                        friend.append((frid, frname))
            #获取我的粉丝中还不是我的关注对象
            fanNotAttention = list(set(fan).difference(set(friend)))
            nu = len(fanNotAttention)
            if nu == 0:
                return render_template('noattentionok.html', nu=nu)
            else:
                return render_template('noattention.html',
                                       nu=nu,
                                       fanNotAttention=fanNotAttention)

        except:
            info = "亲,系统繁忙,请稍后再试......,系统在3秒后自动返回..."
            return render_template('error.html', info=info.decode('utf-8'))
Example #7
0
 def GET(self):
     access_token=session.get('access_token',None)
     if not access_token:
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET,web.ctx.get('homedomain')+'/callback')
         #获得新浪微博的认证url地址
         auth_url = auth.get_authorization_url()
         logger.debug("认证地址为:%s"%auth_url)
         #在session中保存request_token,用于在新浪微博认证通过后换取access_token
         session.request_token=auth.request_token
         web.seeother(auth_url)
     else:
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
         auth.access_token=access_token
         api=API(auth)
         user=api.verify_credentials()
         friends=api.friends()
         return render_template('index.html',friends=friends,user=user)
Example #8
0
 def GET(self):
     access_token = session.get('access_token', None)
     if not access_token:
         """ 
          key.py中放置了开发者的信息 
          """
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET,
                             web.ctx.get('homedomain') + '/callback')
         #获取授权url
         auth_url = auth.get_authorization_url()
         session.request_token = auth.request_token
         web.seeother(auth_url)
     else:
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
         auth.access_token = access_token
         api = API(auth)
         user = api.verify_credentials()
         return render_template('index.html', user=user)
Example #9
0
    def GET(self):
        data = web.input()
        try:
            select = data.star
        except:
            try:
                select = data.hobby
            except:
                try:
                    select = data.personality
                except:
                    select = data.job
        try:
            auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
            auth.access_token = session['access_token']
            api = API(auth)
            seuid = []
            nu = 0
            """ 
            这里写的很不好..... 
            """
            while True:
                re = cursor.execute(
                    'select uid from taginfo where tagid=%d limit 20' %
                    select).fetchall()
                for r in re:
                    seuid.append(r[0])
                for s in seuid:
                    try:
                        api.create_friendship(user_id=s)
                        nu += 1
                    except:
                        continue
                if nu >= 50:
                    break

            info = "恭喜您已成功关注%d位用户....." % nu
            return render_template('success.html', info=info.decode('utf-8'))
        except:
            info = "亲,系统繁忙,请稍后再试......,系统在3秒后自动返回..."
            return render_template('error.html', info=info.decode('utf-8'))
Example #10
0
 def get_auth(self):
   from weibopy.auth import OAuthHandler
   from weibopy.oauth import OAuthToken
   auth = OAuthHandler(settings.SINA_CONSUMER_KEY, settings.SINA_CONSUMER_SECRET)
   auth.access_token = OAuthToken(self.access_token, self.access_secret)
   return auth