当前位置: 首页>>代码示例>>Python>>正文


Python Twython.getFollowersIDs方法代码示例

本文整理汇总了Python中twython.Twython.getFollowersIDs方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.getFollowersIDs方法的具体用法?Python Twython.getFollowersIDs怎么用?Python Twython.getFollowersIDs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twython.Twython的用法示例。


在下文中一共展示了Twython.getFollowersIDs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
def index(request):
	usuario = "@Jandrey15"#definimos una variable 

	twitter = Twython()#creamos un objeto la clase Twython

	followers = twitter.getFollowersIDs( screen_name = usuario)#traemos los usuarios muy facil
    #tweets = twitter.getPublicTimeline()

	return HttpResponse(followers)
开发者ID:johnsi15,项目名称:Python-Django,代码行数:11,代码来源:views.py

示例2: TwitterStats

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
class TwitterStats():
    def __init__(self):
        # connect to twitter api
        self.twitter = Twython(
                        app_key=settings.consumer_key,
                        app_secret=settings.consumer_secret,
                        oauth_token=settings.oauth_token,
                        oauth_token_secret=settings.oauth_token_secret
                        )

    def init_storage(self):
        storage = shelve.open('twitter_stats', writeback=True)

        if not storage:
            storage['followers'] = set()
            storage['unfollowers'] = []
            storage['unfollowers_since_last_check'] = None
            storage['last_update'] = None

        return storage

    def get_followers(self):
        follower_ids = self.twitter.getFollowersIDs()['ids']

        return set(follower_ids)

    def show_screen_name(self, user_id):
        user = self.twitter.showUser(user_id=user_id)
        screen_name = user['screen_name']

        return screen_name

    def update_unfollower_stats(self):
        with closing(self.init_storage()) as storage:
            previous_followers = storage['followers']
            current_followers = self.get_followers()

            new_unfollower_ids = previous_followers - current_followers
            
            unfollowers_since_last_check = []

            for follower_id in new_unfollower_ids:
                unfollower = {
                    'id': follower_id,
                    'screen_name': self.show_screen_name(follower_id),
                    'timestamp': datetime.datetime.now().strftime('%b %d %Y %H:%M:%S')
                }

                storage['unfollowers'].append(unfollower)
                unfollowers_since_last_check.append(unfollower)

            storage['followers'] = current_followers
            storage['unfollowers_since_last_check'] = unfollowers_since_last_check
            storage['last_update'] = datetime.datetime.now().strftime('%b %d %Y %H:%M:%S')
开发者ID:bit2pixel,项目名称:watch-twitter-unfollowers,代码行数:56,代码来源:twitter_stats.py

示例3: getUserEgoNetwork

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
	def getUserEgoNetwork (self, userName):
		#Returns the ego centric net for a user
		twitter = Twython()
		followers = twitter.getFollowersIDs(screen_name = userName)
		friends = twitter.getFriendsIDs(screen_name = userName)
		symmetricFriendship =set(followers).intersection(set(friends))
		print "--------------FOLLOWERS: %d------------------" %(len(followers))
		for follower_id in followers:
			print "User with ID %s, is following %s" % ( follower_id, userName )
		print "--------------FRIENDSHIP: %d------------------" %(len(friends))
		for friends_id in friends:
			print "%s is friend with user with ID %s" % ( userName, friends_id )
		print "--------------SYMMETRIC: %d------------------" %(len(symmetricFriendship))
		return symmetricFriendship
开发者ID:amirmc,项目名称:signpost,代码行数:16,代码来源:twitterChecker.py

示例4: search_with_tokens

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
def search_with_tokens(tokens, queryType, params):
    #print "params = ", params
    #user = UserSocialAuth.objects.filter(user=request.user).get()
    # Set up a new Twython object with the OAuth keys

    #pprint(tokens)
    print "app_key = ", settings.TWITTER_CONSUMER_KEY
    print "app_secret = ", settings.TWITTER_CONSUMER_SECRET
    print "oauth_token = ", tokens['oauth_token']
    print "oauth_token_secret = ", tokens['oauth_token_secret']
    t = Twython(app_key=settings.TWITTER_CONSUMER_KEY,
        app_secret=settings.TWITTER_CONSUMER_SECRET,
        oauth_token=tokens['oauth_token'],
        oauth_token_secret=tokens['oauth_token_secret'])

    # Obtain Twitter results using user's OAuth key
    if queryType == "search":
        params = params.copy()
        pageID = params["pageID"]
        del params["pageID"]
        queryResults = t.search(**(params))

        # Use helper to update the tweet list of the page
        # Return an array of tweets to return to the client
        helper = Helper()
        # tweets = helper.updateWikiArticleTweet(pageID, queryResults) # Update the correct pageID
        helper.updateWikiArticleTweet(pageID, queryResults) # Update the correct pageID
        '''
        tweetsSerialization = []
        for tweet in tweets:
            tweetsSerialization.append({
                "id" : tweet.id,
                "text" : tweet.text,
                "source" : tweet.source,
                "profileImageUrl" : tweet.profileImageUrl,
                "createdAt" : tweet.createdAt
            })
        '''

        # Get the correct logger based on convention:
        # {APP}.{FILE}.{FUNCTION} = __name__.'.'.inspect.stack()[0][3]
        # Need to evaulate performance of 'inspect' library as print function name
        # is not supported by Python
        #print __name__+"."+inspect.stack()[0][3]
        logger = logging.getLogger(__name__+"."+inspect.stack()[0][3])
        # Fake infomation, to be updated later
        logger.info(json.dumps({
            "pageID": pageID, # Pass the correct pageID here
            "queryType": queryType,
            "query": queryResults["search_metadata"]["query"],
            "tweetsCount": queryResults["search_metadata"]["count"],
            "source": 'TwitterAPI',
        }))
        return HttpResponse(json.dumps(queryResults), content_type="application/json")

##    elif queryType == "articleSearch":
##        params1 = dict(params)
##        # TODO, swap this out later
##        params1["q"] = unicode(params["articleId"])
##        del params1["articleId"]
##        queryResults = t.search(**(params1))
    elif queryType == "followersID":
        queryResults = t.getFollowersIDs(**(params))
    elif queryType == "followersList":
        params = params.copy()
        screen_name = params["screen_name"]
        cursor = params["cursor"]
        queryResults = t.getFollowersList(**(params))
        # Save results
        helper = Helper()
        helper.getUserFollower(screen_name, queryResults)
    elif queryType == "friendsID":
        queryResults = t.getFriendsIDs(**(params))
    elif queryType == "friendshipLookup":
        queryResults = t.lookupFriendships(**(params))
    elif queryType == "stream":
        queryResults = t.stream(params, on_results)

    return HttpResponse(json.dumps(queryResults), content_type="application/json")
开发者ID:XuChen-Repair,项目名称:Trendspedia2,代码行数:81,代码来源:views.py

示例5: Twython

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
from twython import Twython
usuario = "ajamaica"
twitter = Twython()
followers = twitter.getFollowersIDs( screen_name = usuario )

for follower_id in followers :
    print "Usuarios %d sigue a %s" % (follower_id, usuario)

tweets = twitter.getPublicTimeline()

for tweet in tweets :
    print tweet['user']['name'].encode('utf-8')
    print tweet['text'].encode('utf-8')

results = twitter.getDailyTrends()

for i in range(0,100) :
    print i

for time, trend_list in results['trends'].iteritems() :
    print time
    for trend in trend_list :
        print trend['query']
开发者ID:manjescc,项目名称:Mejorandola,代码行数:25,代码来源:twython.py

示例6: DBTweetGetter

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]

#.........这里部分代码省略.........
                if ("The URI requested is invalid" in str(detail)) or ("Unauthorized" in str(detail)):
                    print "User " + screen_name + " does not exist."
                    sleep(8)
                    return "FAIL"
                elif "suspended" in str(detail):
                    print "Some Twitter error: " + str(detail)
                    gotry=True
                    sleep(3600)
                else:
                    print "Some Twitter error: " + str(detail)
                    gotry=True
                    sleep(300)
        sleep(8)
        return d["id_str"]

    def getUserDescription(self, screen_name):
        gotry=True
        while gotry==True:
            try:
                d=self.twython.showUser(screen_name=screen_name, entities="false")
                gotry=False
            except Exception as detail:
                if ("The URI requested is invalid" in str(detail)) or ("Unauthorized" in str(detail)) or ("An error occurred processing your request" in str(detail)):
                    print "User " + screen_name + " does not exist."
                    sleep(5)
                    return "FAIL"
                elif "suspended" in str(detail):
                    print "Some Twitter error: " + str(detail)
                    #sleep(300)
                    return "FAIL"

                else:
                    print "Some Twitter error: " + str(detail)
                    gotry=True
                    sleep(5)
        sleep(3)
        return d["description"]

    def getFriends(self, name, friendslist, cursor):
        #Recursively get followers
        sleep(8)
        #print "Getting Friends:" + name
        while True:
            try:
                d=self.twython.getFriendsIDs(screen_name=name, cursor=str(cursor))
                cursor=d["next_cursor"]
                #print str(cursor)
                break
            except Exception as detail:
                print "Some Twitter error: " + str(detail)
                print name
                print str(cursor)
                if ("The URI requested is invalid" in str(detail)) or ("Unauthorized" in str(detail)):
                    print name
                    cursor=-1
                    return "FAIL"
                elif "suspended" in str(detail):
                    sleep(3600)
                else:
                    sleep(300)
        friendslist=friendslist+d["ids"]
                    

        if cursor>0:
            sleep(7)
            friendslist=self.getFriends(name, friendslist, cursor)
        # else:
        return friendslist

    def getFollowers(self, name, followerslist, cursor):
        #Recursively get followers
        sleep(7)
        #print "Getting Followers:" + name
        while True:
            try:
                d=self.twython.getFollowersIDs(screen_name=name, cursor=str(cursor))
                cursor=d["next_cursor"]
                #print str(cursor)
                break
            except Exception as detail:
                print "Some Twitter error: " + str(detail)
                print name
                print str(cursor)
                if ("The URI requested is invalid" in str(detail)) or ("Unauthorized" in str(detail)):
                    cursor=-1
                    return "FAIL"
                elif "suspended" in str(detail):
                    sleep(3600)
                else:
                    sleep(300)

        followerslist=followerslist+d["ids"]
        # print name + ": " +str(len(followerslist))

            
        if cursor>0:
            sleep(7)
            followerslist=self.getFollowers(name, followerslist, cursor)
        # print len(followerslist)
        return followerslist
开发者ID:jamesmcm,项目名称:ClimateChangeTwitter,代码行数:104,代码来源:classtweetgetter.py

示例7: Twython

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
from twython import Twython
import string
import urllib2
from lxml import etree
import StringIO

twitter = Twython()
data_raw = twitter.getFollowersIDs(screen_name = "ionainstitute")

followers = data_raw['ids']
dict = {'noloc': 0}
# print followers

for id in followers:
	url = "http://twitter.com/account/redirect_by_id?id=" + str(id)

	try:
		htmldata = urllib2.urlopen(url)
		html = htmldata.read()

		parser = etree.HTMLParser()
		tree = etree.parse(StringIO.StringIO(html), parser)

		xpath = '/html/body/div/div[3]/div/div[2]/div/div[2]/p[2]/span/text()'

		pre_result1 = ' '.join(tree.xpath(xpath))
		pre_result = pre_result1.strip()

		decode_pre_result = pre_result.decode('string_escape')

		print str(id) + " : " + decode_pre_result
开发者ID:lithiumoxide,项目名称:twatter,代码行数:33,代码来源:tw.py

示例8: __init__

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
class Bot:
    """ The twitter bot class """
    def __init__(self, bot):
        self.twython_obj = Twython(app_key=bot.consumer_key,
                                   app_secret=bot.consumer_secret,
                                   oauth_token=bot.access_token,
                                   oauth_token_secret=bot.access_token_secret)
        self.keywords = bot.keywords
        self.source_user_ids = bot.source_user_ids
        self.source_followers_ids = bot.source_followers_ids
        self.followers_ids = bot.followers_ids


    def get_source_user_ids(self):
        """ Get some users to initiate the twitter bot for the given keywords"""
        source_user_ids = []
        for keyword in self.keywords:
            # get a list of user objects by searching for the keyword
            userlist = self.twython_obj.searchUsers(q=keyword)
            # select 3 random user objects
            random_list = random.sample(userlist, 3)
            # store the screen_name of the 5 users in a list
            ids = [user['id'] for user in random_list]
            #add screen_names to the list of our tweet sources
            source_user_ids = source_user_ids + ids

        for keyword in self.keywords:
            # get a list of recent tweets
            tweetlist = self.twython_obj.search(q=keyword, result_type="recent", lang='en')['results']
            # select 7 random tweets
            random_list = random.sample(tweetlist, 7)
            # store screen_names of users who made the tweets
            ids = [tweet['from_user_id'] for tweet in random_list]
            #add screen_names to the list of our tweet sources
            source_user_ids = source_user_ids + ids

        self.source_user_ids = source_user_ids

        return source_user_ids

    def get_source_followers_ids(self):
        """ Returns a list of all followers of the users in source_users"""
        source_followers_ids = []
        for source_user_id in self.source_user_ids:
            follower_ids = self.twython_obj.getFollowersIDs(user_id=source_user_id)['ids']
            source_followers_ids = source_followers_ids + follower_ids

        self.source_followers_ids = source_followers_ids

        return source_followers_ids

    def find_and_follow(self):
        """ Find users to follow and follow them """
        # Randomly select one keyword from the list of keywords
        keyword = random.choice(self.keywords)
        # Seacrh for tweets with that keyword
        tweets = self.twython_obj.search(q=keyword, result_type="recent", lang='en')['results']

        done_following = False
        while not done_following:
            # Randomly select a tweet
            tweet = random.choice(tweets)
            user_id = tweet['from_user_id']
            if user_id not in self.source_user_ids and user_id not in self.source_followers_ids:
                self.twython_obj.createFriendship(user_id=user_id)
                done_following = True

        return done_following

    def get_follwers(self):
        """ Returns a list of ids of all followers of the bot """
        followers_ids = self.twython_obj.getFollowersIDs(user_id=user_id)['ids']
        self.followers_ids = followers
        return followers_ids

    def copy_and_tweet(self):
        """ Copy a tweet and tweet it """
开发者ID:jokiez88,项目名称:Le-me-no-bot,代码行数:79,代码来源:twitter_helpers.py

示例9: Twython

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFollowersIDs [as 别名]
from twython import Twython

usuario = "andrey"#definimos una variable 
twitter = Twython()#creamos un objeto la clase Twython

followers = twitter.getFollowersIDs( screen_name = usuario)#traemos los usuarios muy facil

for follower_id in followers:
	print "Usuario %d sigue a %s"%(follower_id,usuario)

tweets = twitter.getPublicTimeline()#traemos los twees

for tweet in tweets:
	print tweet['user']['name'].encode('utf-8')
	print tweet['text'].encode('utf-8')


results = twitter.getDailytrends()#usando el objeto usamos ese metodo

#esto se llama o se dice iterar objetos
for time, trend_list in results['trends'].iteritems():
	print time
	for trend in trend_list:
		print trend['query']
开发者ID:johnsi15,项目名称:Python-Django,代码行数:26,代码来源:claseJamaica.py


注:本文中的twython.Twython.getFollowersIDs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。