Last active
May 24, 2017 07:18
-
-
Save naari3/f13367c5f34cd43f4631f06f1e0b1c43 to your computer and use it in GitHub Desktop.
Tweepyでstreaming apiを使用した自動フォロー返し ref: http://qiita.com/naari/items/fa44a318dad81c8c627f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.me = self.api.me() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
consumer_key = "CONSUMER_KEY" | |
consumer_secret = "CONSUMER_SECRET" | |
access_token = "ACCESS_TOKEN" | |
access_secret = "ACCESS_TOKEN_SECRET" | |
class StreamListener(tweepy.StreamListener): | |
def __init__(self, api): | |
super().__init__(api) | |
self.me = self.api.me() | |
def on_event(self, event): | |
if event.event == 'follow': | |
if self.me.id != source_user["id"]: | |
source_user = event.source | |
event._api.create_friendship(source_user["id"]) | |
print("followed by {} {}".format(source_user["name"], source_user["screen_name"])) | |
if __name__ == "__main__": | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_secret) | |
api = tweepy.API(auth) | |
stream = tweepy.Stream(auth=api.auth, listener=StreamListener(api)) | |
stream.userstream(_with="user") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if self.me.id != source_user["id"]: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment