def _change_profile_picture(self, twitter, followers, probability): """Randomly change the profile picture with one of the followers""" if (random.random() * 100) >= probability: return api_url = "%s/account/update_profile_image.json" % twitter.base_url follower_clone = random.choice(followers) if not follower_clone: return profile_image_url = follower_clone.GetProfileImageUrl() screen_name = follower_clone.GetScreenName() hook = oauth_hook.OAuthHook(access_token=twitter._access_token_key, access_token_secret=twitter._access_token_secret, consumer_key=twitter._consumer_key, consumer_secret=twitter._consumer_secret, header_auth=True) client = requests.session(hooks={'pre_request': hook}) log.debug("fetching new profile picture %s", profile_image_url) image_file = StringIO.StringIO(twitter._FetchUrl(profile_image_url)) response = client.post(api_url, files={"image" : image_file}) # abusing python-twitter internal API, checks if the response contains an error twitter._ParseAndCheckTwitter(response.content) log.info("changed profile picture with @%s's (%s)", screen_name, profile_image_url)
def similarKeywords(self,keyword): """Use the tweetag API to get keywords related to a keyword.""" url = 'http://api.tweetag.com/tagcloud/%s' % keyword print url json = twitter._FetchUrl(url) print json data = simplejson.loads(json) l = sorted([[str(d['name']),d['weight']] for d in data if (type(d['weight'])==int)],key=operator.itemgetter(1)) l.reverse() return l