Stop using the Streaming API endpoints. Closes #213. Needs testing

This commit is contained in:
Manuel Cortez 2018-05-25 12:11:53 -05:00
parent f2ea4136c0
commit 7d35dbc752

View File

@ -345,40 +345,44 @@ class Session(object):
def start_streaming(self): def start_streaming(self):
""" Start the streaming for sending tweets in realtime.""" """ Start the streaming for sending tweets in realtime."""
if not hasattr(self, "main_stream"): if application.streaming_lives():
self.get_timelines() if not hasattr(self, "main_stream"):
if not hasattr(self, "timelinesStream"): self.get_timelines()
self.get_main_stream() if not hasattr(self, "timelinesStream"):
self.get_main_stream()
def get_main_stream(self): def get_main_stream(self):
log.debug("Starting the main stream...") if application.streaming_lives():
self.main_stream = twitter.buffers.stream.streamer(keyring.get("api_key"), keyring.get("api_secret"), self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], self) log.debug("Starting the main stream...")
stream_threaded(self.main_stream.user, self.session_id) self.main_stream = twitter.buffers.stream.streamer(keyring.get("api_key"), keyring.get("api_secret"), self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], self)
stream_threaded(self.main_stream.user, self.session_id)
def get_timelines(self): def get_timelines(self):
log.debug("Starting the timelines stream...") if application.streaming_lives():
self.timelinesStream = twitter.buffers.indibidual.timelinesStreamer(keyring.get("api_key"), keyring.get("api_secret"), self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], session=self) log.debug("Starting the timelines stream...")
ids = "" self.timelinesStream = twitter.buffers.indibidual.timelinesStreamer(keyring.get("api_key"), keyring.get("api_secret"), self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], session=self)
for i in self.settings["other_buffers"]["timelines"]: ids = ""
ids = ids + "%s, " % (self.db[i+"-timeline"][0]["user"]["id_str"]) for i in self.settings["other_buffers"]["timelines"]:
for i in self.lists: ids = ids + "%s, " % (self.db[i+"-timeline"][0]["user"]["id_str"])
for z in i.users: for i in self.lists:
ids += str(z) + ", " for z in i.users:
if ids != "": ids += str(z) + ", "
stream_threaded(self.timelinesStream.statuses.filter, self.session_id, follow=ids) if ids != "":
stream_threaded(self.timelinesStream.statuses.filter, self.session_id, follow=ids)
def add_friends(self): def add_friends(self):
try: if application.streaming_lives():
self.timelinesStream.set_friends(self.main_stream.friends) try:
except AttributeError: self.timelinesStream.set_friends(self.main_stream.friends)
pass except AttributeError:
pass
def listen_stream_error(self): def listen_stream_error(self):
if hasattr(self, "main_stream"): if hasattr(self, "main_stream") and application.streaming_lives():
log.debug("Disconnecting the main stream...") log.debug("Disconnecting the main stream...")
self.main_stream.disconnect() self.main_stream.disconnect()
del self.main_stream del self.main_stream
if hasattr(self, "timelinesStream"): if hasattr(self, "timelinesStream") and application.streaming_lives():
log.debug("disconnecting the timelines stream...") log.debug("disconnecting the timelines stream...")
self.timelinesStream.disconnect() self.timelinesStream.disconnect()
del self.timelinesStream del self.timelinesStream
@ -394,9 +398,9 @@ class Session(object):
pub.sendMessage("restart_streams", session=self.session_id) pub.sendMessage("restart_streams", session=self.session_id)
if self.reconnection_function_active == True: return if self.reconnection_function_active == True: return
self.reconnection_function_active = True self.reconnection_function_active = True
if not hasattr(self, "main_stream"): if not hasattr(self, "main_stream") or not application.streaming_lives():
self.get_main_stream() self.get_main_stream()
if not hasattr(self, "timelinesStream"): if not hasattr(self, "timelinesStream") or application.streaming_lives():
self.get_timelines() self.get_timelines()
self.reconnection_function_active = False self.reconnection_function_active = False
if hasattr(self, "timelinesStream") and not hasattr(self.timelinesStream, "friends"): if hasattr(self, "timelinesStream") and not hasattr(self.timelinesStream, "friends"):
@ -407,13 +411,14 @@ class Session(object):
# pub.sendMessage("stream-error", session=self.session_id) # pub.sendMessage("stream-error", session=self.session_id)
def remove_stream(self, stream): def remove_stream(self, stream):
if stream == "timelinesStream": if application.streaming_lives():
if hasattr(self, "timelinesStream"): if stream == "timelinesStream":
self.timelinesStream.disconnect() if hasattr(self, "timelinesStream"):
del self.timelinesStream self.timelinesStream.disconnect()
else: del self.timelinesStream
self.main_stream.disconnect() else:
del self.main_stream self.main_stream.disconnect()
del self.main_stream
def shelve(self): def shelve(self):
"Shelve the database to allow for persistance." "Shelve the database to allow for persistance."