Python - Tweepy - How to use lookup_friendships?
<p>I'm trying to figure out if I'm following a user from which the streaming API just received a tweet. If I don't, then I want to follow him.</p>

<p>I've got something like:</p>

<pre><code>def checkFollow(status):
    relationship = api.lookup_friendships("Privacy_Watch_",status.user.id_str)
</code></pre>

<p>From there, how do I check if I follow this user already?</p>

<p>The lookup_friendships method will return everyone you follow each time you call it, in blocks of 100 users. Provided you follow a lot of people, that will be highly inefficient and consume a lot of requests.</p>

<p>You can use instead the <a href="https://github.com/tweepy/tweepy/blob/master/tweepy/api.py#L461" rel="nofollow">show_friendship</a> method, it will return a JSON containing <a href="https://dev.twitter.com/rest/reference/get/friendships/show" rel="nofollow">information</a> about your relationship with the id provided.</p>

<p>I cannot test it right now, but the following code should do what you want:</p>

<pre><code>def checkFollow(status):
    relation = api.show_friendship(source_screen_name=your_user_name, target_screen_name=status.user.id_str)
    if relation.target.following: #I'm not sure if it should be "target" or "source" here
        return True
    return False
</code></pre>

python twitter tweepy