예제 #1
0
파일: data.py 프로젝트: shch/weibo
 def getFollows(self,name):
     self.auth.setToken(self.key,self.secret)
     api = API(self.auth)
     try:
         follows = api.followers_ids(screen_name=name)
     except Exception ,e:
         print e
예제 #2
0
파일: ids.py 프로젝트: shunsunsun/Research
class Test(unittest.TestCase):

    consumer_key = ''
    consumer_secret = ''

    def __init__(self):
        """ constructor """

    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''

    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)

    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth, source=source)

    def friends_ids(self):
        fids = self.api.friends_ids()
        self.obj = fids
        ids = self.getAtt("ids")
        next_cursor = self.getAtt("next_cursor")
        previous_cursor = self.getAtt("previous_cursor")
        print("friends_ids---" + str(ids) + ":next_cursor" + str(next_cursor) +
              ":previous_cursor" + str(previous_cursor))

    def followers_ids(self):
        fids = self.api.followers_ids()
        self.obj = fids
        ids = self.getAtt("ids")
        next_cursor = self.getAtt("next_cursor")
        previous_cursor = self.getAtt("previous_cursor")
        print("followers_ids---" + str(ids) + ":next_cursor" +
              str(next_cursor) + ":previous_cursor" + str(previous_cursor))
예제 #3
0
파일: ids.py 프로젝트: chengjun/Research
class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
    
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
        
    def basicAuth(self, source, username, password):
        self.auth = BasicAuthHandler(username, password)
        self.api = API(self.auth,source=source)
    
    def friends_ids(self):
        fids = self.api.friends_ids()
        self.obj = fids
        ids = self.getAtt("ids")
        next_cursor = self.getAtt("next_cursor")
        previous_cursor = self.getAtt("previous_cursor")
        print("friends_ids---"+ str(ids) +":next_cursor"+ str(next_cursor) +":previous_cursor"+ str(previous_cursor))
        
    def followers_ids(self):
        fids = self.api.followers_ids()
        self.obj = fids
        ids = self.getAtt("ids")
        next_cursor = self.getAtt("next_cursor")
        previous_cursor = self.getAtt("previous_cursor")
        print("followers_ids---"+ str(ids) +":next_cursor"+ str(next_cursor) +":previous_cursor"+ str(previous_cursor))
예제 #4
0
파일: web.py 프로젝트: wangsongf/python
class Setag(threading.Thread):
    """ 
这个线程主要是用来搜索用户tag,如果满足tag要求就写入数据库中, 
    """
    def authorization(self):
        """ 
        开发者认证 
        """
        auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
        auth.setToken(key.TOKEN, key.TOKEN_SECRET)
        self.api = API(auth)
        self.cursor = cursor

    def adduser(self, uid):
        """ 
        遍历uid用户的tag,满足条件加入数据库 
        """
        try:
            fan = self.api.followers_ids(uid)
            fanuid = fan.ids
            for id in fanuid:
                tags = self.api.tags(id)
                tt = []
                for t in tags:
                    tagid = t.__getattribute__('id')
                    value = t.__getattribute__(tagid)
                    tt.append(value.encode('utf-8'))
                """ 
                获取用户tag与要求标签的交集 
                """
                common = set(tt).intersection(set(systag))
                if len(common) == 0:
                    continue
                else:
                    for t in common:
                        """ 
                        获取tag对应的tagid 
                        """
                        tagindex = tagdict[t]
                        try:
                            self.cursor.execute(
                                "insert into taginfo(uid,tagid) values(%d,%d)"
                                % (int(id), int(tagindex)))
                            conn.commit()
                        except:
                            continue
        except:
            time.sleep(120)
            pass
        finally:
            time.sleep(60)
            """ 
            将uid用户的第一个粉丝uid传给adduser 
            """
            return self.adduser(fanuid[0])

    def run(self):
        self.authorization()
        me = self.api.verify_credentials()
        """ 
        将我自己的uid给adduser 
        """
        self.adduser(me.id)