Esempio n. 1
0
 def friendship(self):
     ids = IDS.get()
     friends   = set(simplejson.loads(ids.friends))
     followers = set(simplejson.loads(ids.followers))
     should_follow   = list(followers - friends)
     should_unfollow = list(friends - followers)
     random.shuffle(should_follow)
     random.shuffle(should_unfollow)
     logging.debug('should follow: %d' % len(should_follow))
     logging.debug('should unfollow: %d' % len(should_unfollow))
     # 繰り返し挑戦するので失敗してもタイムアウトになっても気にしない
     while len(should_follow) > 0 or len(should_unfollow) > 0:
         if len(should_follow) > 0:
             url = 'http://api.twitter.com/1/friendships/create.json'
             logging.debug(url)
             result = self.client.make_request(
                 url,
                 token   = self.bot_config['access_token'],
                 secret  = self.bot_config['access_token_secret'],
                 additional_params = {"user_id" : should_follow.pop()},
                 protected         = True,
                 method            = urlfetch.POST)
             if result.status_code != 200:
                 logging.warn(result.content)
         if len(should_unfollow) > 0:
             url = 'http://api.twitter.com/1/friendships/destroy.json'
             result = self.client.make_request(
                 url,
                 token   = self.bot_config['access_token'],
                 secret  = self.bot_config['access_token_secret'],
                 additional_params = {"user_id" : should_follow.pop()},
                 protected         = True,
                 method            = urlfetch.POST)
             if result.status_code != 200:
                 logging.warn(result.content)
Esempio n. 2
0
 def followers(self):
     url = 'http://api.twitter.com/1/followers/ids.json'
     result = self.client.make_request(
         url,
         token   = self.bot_config['access_token'],
         secret  = self.bot_config['access_token_secret'],
         additional_params = None,
         protected         = True,
         method            = urlfetch.GET)
     logging.debug(result.status_code)
     logging.debug(result.content)
     if result.status_code == 200:
         ids = IDS.get()
         ids.followers = result.content
         ids.put()