tweepy Async Streaming
server = server_id : int
Tchan = server.get_channel(channel_id : int)
import tweepy
api_key = "string" #also called consumer key
api_key_secret = "string" #also called consumer key secret
access_token = "string-8z95tnY8Fid91sFUxACJeMQWv4RsI6D"
access_token_secret = "string"
authenticator = tweepy.OAuthHandler(api_key, api_key_secret)
authenticator.set_access_token(access_token, access_token_secret)
api = tweepy.API(authenticator, wait_on_rate_limit=True)
#Requires Tweepy 4.0.0-alpha
from tweepy.asynchronous.streaming import AsyncStream
class AsyncStream(tweepy.asynchronous.AsyncStream):
async def on_status(self, status):
#make sure this is a real tweet
if hasattr(status, 'retweeted_status'):
return False
elif status.in_reply_to_status_id != None:
return False
elif status.in_reply_to_screen_name != None:
return False
elif status.in_reply_to_user_id != None:
return False
else:
#sends the tweet's content to the channel
await Tchan.send(status.text)
myStream = AsyncStream(api_key, api_key_secret, access_token, access_token_secret)
myStream.filter(track=["python"]) #start the stream