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


Python Twython.getFriendsIDs方法代码示例

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


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

示例1: userFriends

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFriendsIDs [as 别名]
def userFriends(user=''):
	twitter = Twython()
	friends = twitter.getFriendsIDs(screen_name=user)["ids"]
	friend_list=''
	friends_bio=''
	i=0
	for friend in friends:
		friend_list += str(friend) + ','
		if((i+1)%100==0):
			aux = twitter.lookupUser(user_id=friend_list[:-1])
			for x in aux:
				try:
					friends_bio += x['description'].encode('ascii', 'replace')
				except:
					pass
			print friends_bio
			friend_list=''
			sleep(10)
		i+=1
	#for i in range(len(friends)):
	#	friend_list = friend_list + str(friends[i]) + ','
	#	print i, friend_list
	#	if((i+1)%100==0):
	#		aux = twitter.lookupUser(user_id=friend_list[:-1])
	#		print friend_list
	#		for x in range(100):
	#			print x
	#			friends_bio += aux[x]['description'].encode('ascii', 'replace')
	#			friends_bio += ' '
	#		sleep(5)
	#	friend_list=''
	#lookup = twitter.lookupUser(user_id=friend_list)
	return friends_bio
开发者ID:alvarofaundez,项目名称:SmartboxTv,代码行数:35,代码来源:server.py

示例2: getUserEgoNetwork

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFriendsIDs [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

示例3: friends

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFriendsIDs [as 别名]
def friends(request):
    """
        An example view with Twython/OAuth hooks/calls to fetch data about the user
        in question. Pretty self explanatory if you read through it...
    """
    user = request.user.twitterprofile
    twitter = Twython(
        twitter_token=settings.TWITTER_KEY,
        twitter_secret=settings.TWITTER_SECRET,
        oauth_token=user.oauth_token,
        oauth_token_secret=user.oauth_secret,
    )
    # user_tweets = twitter.getHomeTimeline()
    user_friends_ids = twitter.getFriendsIDs()["ids"]
    friends_details = twitter.lookupUser(user_id=user_friends_ids)

    return render_to_response("friends.html", {"friends": friends_details})
开发者ID:benregn,项目名称:twitter_favorites,代码行数:19,代码来源:views.py

示例4: all_favorites

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFriendsIDs [as 别名]
def all_favorites(request):
    user = request.user.twitterprofile
    twitter = Twython(
        twitter_token=settings.TWITTER_KEY,
        twitter_secret=settings.TWITTER_SECRET,
        oauth_token=user.oauth_token,
        oauth_token_secret=user.oauth_secret,
    )
    user_friends_ids = twitter.getFriendsIDs()["ids"]
    # friends_details = twitter.lookupUser(user_id=user_friends_ids)
    all_favorites = []
    for friend in user_friends_ids:
        all_favorites.append(twitter.getFavorites(user_id=friend, count=200))

    all_favorites = list(itertools.chain.from_iterable(all_favorites))

    return render_to_response("all_favorites.html", {"all_favorites": all_favorites})
开发者ID:benregn,项目名称:twitter_favorites,代码行数:19,代码来源:views.py

示例5: search_with_tokens

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFriendsIDs [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

示例6: DBTweetGetter

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFriendsIDs [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: Flask

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

app = Flask(__name__)


app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')


db = SQLAlchemy(app)

tavorite = Twython(app_key=os.environ['CONSUMER_KEY'],
                   app_secret=os.environ['CONSUMER_SECRET'],
                   oauth_token=os.environ['ACCESS_TOKEN'],
                   oauth_token_secret=os.environ['ACCESS_TOKEN_SECRET'])

following = tavorite.getFriendsIDs()['ids']

@app.route('/')
def home():
    links = Tweet.query.filter_by(url_exists=True).order_by(Tweet.score_with_time.desc()).filter(Tweet.main_url != 'instagram.com', Tweet.main_url != 'www.instagram.com', Tweet.main_url != 'instagr.am', Tweet.main_url != 'youtube.com', Tweet.main_url != 'www.youtube.com', Tweet.main_url != 'www.vimeo.com', Tweet.main_url != 'twitpic.com', Tweet.main_url != 'www.twitpic.com', Tweet.main_url !='i.imgur.com', Tweet.main_url != 'www.yfrog.com',Tweet.main_url != 'twitter.yfrog.com', Tweet.main_url != 'twitter.com', Tweet.main_url != 'imgur.com').limit(30).all()
    time = tweets_age_for_view(links) 
    #links = list_of_links(Nava_rank.rt_count)

    ### NEEDS A FILTER FOR MEDIA LINKS
    return render_template('show_links.html', links=links, time=time)

@app.route('/best')
def best():
    links = Tweet.query.filter_by(url_exists=True).order_by(Tweet.score.desc()).filter(Tweet.main_url != 'instagram.com', Tweet.main_url != 'www.instagram.com', Tweet.main_url != 'instagr.am', Tweet.main_url != 'youtube.com', Tweet.main_url != 'www.youtube.com', Tweet.main_url != 'www.vimeo.com', Tweet.main_url != 'twitpic.com', Tweet.main_url != 'www.twitpic.com', Tweet.main_url !='i.imgur.com', Tweet.main_url != 'www.yfrog.com').limit(50).all()

    #links = list_of_links(Nava_rank.rt_count)
开发者ID:fnava621,项目名称:NavaNews,代码行数:32,代码来源:nava_rank.py

示例8: Flask

# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import getFriendsIDs [as 别名]
app = Flask(__name__)

app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL")


db = SQLAlchemy(app)

tavorite = Twython(
    app_key=os.environ["CONSUMER_KEY"],
    app_secret=os.environ["CONSUMER_SECRET"],
    oauth_token=os.environ["ACCESS_TOKEN"],
    oauth_token_secret=os.environ["ACCESS_TOKEN_SECRET"],
)

following = tavorite.getFriendsIDs()["ids"]

filter_out_media = [
    "instagram.com",
    "www.instagram.com",
    "instagr.am",
    "youtube.com",
    "www.youtube.com",
    "www.vimeo.com",
    "vimeo.com",
    "twitpic.com",
    "www.twitpic.com",
    "i.imgur.com",
    "www.yfrog.com",
    "twitter.yfrog.com",
    "twitter.com",
开发者ID:fnava621,项目名称:Nava-,代码行数:32,代码来源:app.py


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