mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Exclude muted users from Streaming API
This commit is contained in:
parent
37af722556
commit
8fe2f4c64d
@ -504,7 +504,7 @@ class Session(base.baseSession):
|
||||
self.db["users"] = users
|
||||
|
||||
def start_streaming(self):
|
||||
self.stream_listener = streaming.StreamListener(twitter_api=self.twitter, user=self.db["user_name"], user_id=self.db["user_id"])
|
||||
self.stream_listener = streaming.StreamListener(twitter_api=self.twitter, user=self.db["user_name"], user_id=self.db["user_id"], muted_users=self.db["muted_users"])
|
||||
self.stream = streaming.Stream(auth = self.auth, listener=self.stream_listener, chunk_size=1025)
|
||||
self.stream_thread = call_threaded(self.stream.filter, follow=self.stream_listener.users, stall_warnings=True)
|
||||
|
||||
|
@ -14,14 +14,23 @@ log = logging.getLogger("sessions.twitter.streaming")
|
||||
|
||||
class StreamListener(tweepy.StreamListener):
|
||||
|
||||
def __init__(self, twitter_api, user, user_id, *args, **kwargs):
|
||||
def __init__(self, twitter_api, user, user_id, muted_users=[], *args, **kwargs):
|
||||
super(StreamListener, self).__init__(*args, **kwargs)
|
||||
log.debug("Starting streaming listener for account {}".format(user))
|
||||
self.started = False
|
||||
self.users = []
|
||||
self.api = twitter_api
|
||||
self.user = user
|
||||
self.user_id = user_id
|
||||
self.users = [str(id) for id in self.api.friends_ids()]
|
||||
friends = self.api.friends_ids()
|
||||
log.debug("Retrieved {} friends to add to the streaming listener.".format(len(friends)))
|
||||
self.users.append(str(self.user_id))
|
||||
log.debug("Started streaming object for user {}".format(self.user))
|
||||
log.debug("Got {} muted users.".format(len(muted_users)))
|
||||
for user in friends:
|
||||
if user not in muted_users:
|
||||
self.users.append(str(user))
|
||||
self.started = True
|
||||
log.debug("Streaming listener started with {} users to follow.".format(len(self.users)))
|
||||
|
||||
def on_connect(self):
|
||||
pub.sendMessage("streamConnected", user=self.user)
|
||||
|
Loading…
Reference in New Issue
Block a user