Allow streaming API support to be disabled from global settings dialog

This commit is contained in:
Manuel Cortez 2021-07-04 09:44:48 -05:00
parent 03b61946f8
commit e6543bcf77

View File

@ -504,11 +504,16 @@ class Session(base.baseSession):
self.db["users"] = users self.db["users"] = users
def start_streaming(self): def start_streaming(self):
if config.app["app-settings"]["no_streaming"]:
return
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_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 = 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) self.stream_thread = call_threaded(self.stream.filter, follow=self.stream_listener.users, stall_warnings=True)
def stop_streaming(self): def stop_streaming(self):
if config.app["app-settings"]["no_streaming"]:
return
if hasattr(self, "stream"):
self.stream.running = False self.stream.running = False
log.debug("Stream stopped for accounr {}".format(self.db["user_name"])) log.debug("Stream stopped for accounr {}".format(self.db["user_name"]))
@ -555,6 +560,10 @@ class Session(base.baseSession):
pub.sendMessage("newTweet", data=status, user=self.db["user_name"], _buffers=buffers_to_send) pub.sendMessage("newTweet", data=status, user=self.db["user_name"], _buffers=buffers_to_send)
def check_streams(self): def check_streams(self):
if config.app["app-settings"]["no_streaming"]:
return
if not hasattr(self, "stream"):
return
log.debug("Status of running stream for user {}: {}".format(self.db["user_name"], self.stream.running)) log.debug("Status of running stream for user {}: {}".format(self.db["user_name"], self.stream.running))
if self.stream.running == False: if self.stream.running == False:
self.start_streaming() self.start_streaming()