tweepy async streaming

Solutions on MaxInterview for tweepy async streaming by the best coders in the world

showing results for - "tweepy async streaming"
Linus
30 Jun 2018
1server = server_id : int
2Tchan = server.get_channel(channel_id : int)
3
4import tweepy
5api_key = "string" #also called consumer key
6api_key_secret = "string" #also called consumer key secret
7access_token = "string-8z95tnY8Fid91sFUxACJeMQWv4RsI6D"
8access_token_secret = "string"
9authenticator = tweepy.OAuthHandler(api_key, api_key_secret)
10authenticator.set_access_token(access_token, access_token_secret)
11api = tweepy.API(authenticator, wait_on_rate_limit=True)
12
13#Requires Tweepy 4.0.0-alpha
14from tweepy.asynchronous.streaming import AsyncStream
15
16class AsyncStream(tweepy.asynchronous.AsyncStream):
17	async def on_status(self, status):
18		#make sure this is a real tweet
19		if hasattr(status, 'retweeted_status'):
20			return False
21		elif status.in_reply_to_status_id != None:
22			return False
23		elif status.in_reply_to_screen_name != None:
24			return False
25		elif status.in_reply_to_user_id != None:
26			return False
27		else:
28          	#sends the tweet's content to the channel
29			await Tchan.send(status.text)
30
31myStream = AsyncStream(api_key, api_key_secret, access_token, access_token_secret)
32myStream.filter(track=["python"]) #start the stream