mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Some stream improvements
This commit is contained in:
parent
02bdeae4e6
commit
bd1b0b5e32
@ -211,9 +211,9 @@ class baseBufferController(bufferController):
|
|||||||
message = messages.reply(self.session, _(u"Reply"), _(u"Reply to %s") % (screen_name,), "@%s" % (screen_name,), users)
|
message = messages.reply(self.session, _(u"Reply"), _(u"Reply to %s") % (screen_name,), "@%s" % (screen_name,), users)
|
||||||
if message.message.get_response() == widgetUtils.OK:
|
if message.message.get_response() == widgetUtils.OK:
|
||||||
if message.image == None:
|
if message.image == None:
|
||||||
call_threaded(self.session.twitter.api_call, call_name="update_status", _sound="reply_send.ogg", in_reply_to_status_id=id, status=message.message.get_text())
|
call_threaded(self.session.api_call, call_name="update_status", _sound="reply_send.ogg", in_reply_to_status_id=id, status=message.message.get_text())
|
||||||
else:
|
else:
|
||||||
call_threaded(self.session.twitter.api_call, call_name="update_status_with_media", _sound="reply_send.ogg", in_reply_to_status_id=id, status=message.message.get_text(), media=message.file)
|
call_threaded(self.session.api_call, call_name="update_status_with_media", _sound="reply_send.ogg", in_reply_to_status_id=id, status=message.message.get_text(), media=message.file)
|
||||||
|
|
||||||
def direct_message(self, *args, **kwargs):
|
def direct_message(self, *args, **kwargs):
|
||||||
tweet = self.get_tweet()
|
tweet = self.get_tweet()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from wxUI import (view, dialogs, commonMessageDialogs)
|
from wxUI import (view, dialogs, commonMessageDialogs)
|
||||||
import buffersController
|
import buffersController
|
||||||
import messages
|
import messages
|
||||||
from sessionmanager import session
|
from sessionmanager import session as session_
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
import sound
|
import sound
|
||||||
import output
|
import output
|
||||||
@ -13,9 +13,12 @@ import config
|
|||||||
import widgetUtils
|
import widgetUtils
|
||||||
import platform
|
import platform
|
||||||
from extra import SoundsTutorial
|
from extra import SoundsTutorial
|
||||||
|
import logging
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
import keystrokeEditor
|
import keystrokeEditor
|
||||||
|
|
||||||
|
log = logging.getLogger("mainController")
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
|
|
||||||
""" Main Controller for TWBlue. It manages the main window and sessions."""
|
""" Main Controller for TWBlue. It manages the main window and sessions."""
|
||||||
@ -65,6 +68,7 @@ class Controller(object):
|
|||||||
|
|
||||||
def bind_other_events(self):
|
def bind_other_events(self):
|
||||||
pub.subscribe(self.editing_keystroke, "editing_keystroke")
|
pub.subscribe(self.editing_keystroke, "editing_keystroke")
|
||||||
|
pub.subscribe(self.manage_stream_errors, "stream-error")
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.learn_sounds, menuitem=self.view.sounds_tutorial)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.learn_sounds, menuitem=self.view.sounds_tutorial)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.exit, menuitem=self.view.close)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.exit, menuitem=self.view.close)
|
||||||
@ -87,10 +91,14 @@ class Controller(object):
|
|||||||
self.do_work()
|
self.do_work()
|
||||||
|
|
||||||
def do_work(self):
|
def do_work(self):
|
||||||
for i in session.sessions:
|
log.debug("Creating buffers for all sessions...")
|
||||||
self.create_buffers(session.sessions[i])
|
for i in session_.sessions:
|
||||||
call_threaded(self.start_buffers, session.sessions[i])
|
log.debug("Working on session %s" % (i,))
|
||||||
|
self.create_buffers(session_.sessions[i])
|
||||||
|
call_threaded(self.start_buffers, session_.sessions[i])
|
||||||
sound.player.play("tweet_timeline.ogg")
|
sound.player.play("tweet_timeline.ogg")
|
||||||
|
self.checker_function = RepeatingTimer(60, self.check_connection)
|
||||||
|
self.checker_function.start()
|
||||||
|
|
||||||
def create_buffers(self, session):
|
def create_buffers(self, session):
|
||||||
session.get_user_info()
|
session.get_user_info()
|
||||||
@ -222,10 +230,10 @@ class Controller(object):
|
|||||||
buffer.destroy_status()
|
buffer.destroy_status()
|
||||||
|
|
||||||
def exit(self, *args, **kwargs):
|
def exit(self, *args, **kwargs):
|
||||||
for item in session.sessions:
|
for item in session_.sessions:
|
||||||
session.sessions[item].settings.write()
|
session_.sessions[item].settings.write()
|
||||||
session.sessions[item].main_stream.disconnect()
|
session_.sessions[item].main_stream.disconnect()
|
||||||
session.sessions[item].timelinesStream.disconnect()
|
session_.sessions[item].timelinesStream.disconnect()
|
||||||
sound.player.cleaner.cancel()
|
sound.player.cleaner.cancel()
|
||||||
widgetUtils.exit_application()
|
widgetUtils.exit_application()
|
||||||
|
|
||||||
@ -396,10 +404,22 @@ class Controller(object):
|
|||||||
print "i've pressed"
|
print "i've pressed"
|
||||||
|
|
||||||
def start_buffers(self, session):
|
def start_buffers(self, session):
|
||||||
|
log.debug("starting buffers... Session %s" % (session,))
|
||||||
for i in self.buffers:
|
for i in self.buffers:
|
||||||
|
log.debug("Starting %s for %s" % (i.name, session))
|
||||||
if i.session == session and i.needs_init == True:
|
if i.session == session and i.needs_init == True:
|
||||||
i.start_stream()
|
i.start_stream()
|
||||||
|
log.debug("Starting the streaming endpoint")
|
||||||
session.start_streaming()
|
session.start_streaming()
|
||||||
|
|
||||||
|
def manage_stream_errors(self, session):
|
||||||
|
log.error("An error ocurred with the stream for the %s session. It will be destroyed" % (session,))
|
||||||
|
s = sessions_.session[session]
|
||||||
|
s.listen_stream_error()
|
||||||
|
|
||||||
|
def check_connection(self):
|
||||||
|
for i in session_.sessions:
|
||||||
|
session_.sessions[i].check_connection()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
config.app.write()
|
config.app.write()
|
@ -6,8 +6,8 @@ import sys
|
|||||||
|
|
||||||
APP_LOG_FILE = 'debug.log'
|
APP_LOG_FILE = 'debug.log'
|
||||||
ERROR_LOG_FILE = "error.log"
|
ERROR_LOG_FILE = "error.log"
|
||||||
MESSAGE_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s"
|
MESSAGE_FORMAT = u"%(asctime)s %(name)s %(levelname)s: %(message)s"
|
||||||
DATE_FORMAT = "%a %b %d, %Y %H:%M:%S"
|
DATE_FORMAT = u"%b %d, %Y %H:%M:%S"
|
||||||
|
|
||||||
formatter = logging.Formatter(MESSAGE_FORMAT, datefmt=DATE_FORMAT)
|
formatter = logging.Formatter(MESSAGE_FORMAT, datefmt=DATE_FORMAT)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import commandline
|
|||||||
import config
|
import config
|
||||||
import sound
|
import sound
|
||||||
import output
|
import output
|
||||||
|
from logger import logger as logging
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
config.setup()
|
config.setup()
|
||||||
|
@ -11,9 +11,7 @@ def call_threaded(func, *args, **kwargs):
|
|||||||
try:
|
try:
|
||||||
func(*a, **k)
|
func(*a, **k)
|
||||||
except TwythonRateLimitError:
|
except TwythonRateLimitError:
|
||||||
wx.MessageDialog(None, u"Has superado el límite de llamadas a la API que Twitter permite. Eso puede deberse a muchas líneas temporales abiertas, a abrir y cerrar el programa en un periodo corto de tiempo, o a tener muchas llamadas a la API en tu configuración. TW Blue esperará 5 minutos y volverá a intentarlo.", u"Límite de llamadas a la API Superado", wx.ICON_ERROR|wx.OK).ShowModal()
|
pass
|
||||||
time.sleep(300)
|
|
||||||
call_threaded(func, *args, **kwargs)
|
|
||||||
# except:
|
# except:
|
||||||
# pass
|
# pass
|
||||||
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
|
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
|
||||||
@ -23,10 +21,11 @@ def call_threaded(func, *args, **kwargs):
|
|||||||
|
|
||||||
def stream_threaded(func, *args, **kwargs):
|
def stream_threaded(func, *args, **kwargs):
|
||||||
def new_func(*a, **k):
|
def new_func(*a, **k):
|
||||||
|
# global session
|
||||||
try:
|
try:
|
||||||
func(*a, **k)
|
func(**k)
|
||||||
except:
|
except:
|
||||||
pub.sendMessage("streamError")
|
pub.sendMessage("streamError", session=a[0])
|
||||||
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
|
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
|
@ -10,7 +10,7 @@ import sound
|
|||||||
from twitter import utils
|
from twitter import utils
|
||||||
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
||||||
from config_utils import Configuration, ConfigurationResetException
|
from config_utils import Configuration, ConfigurationResetException
|
||||||
from mysc.thread_utils import call_threaded
|
from mysc.thread_utils import stream_threaded
|
||||||
|
|
||||||
sessions = {}
|
sessions = {}
|
||||||
|
|
||||||
@ -88,6 +88,7 @@ class Session(object):
|
|||||||
self.settings = None
|
self.settings = None
|
||||||
self.twitter = twitter.twitter.twitter()
|
self.twitter = twitter.twitter.twitter()
|
||||||
self.db = {}
|
self.db = {}
|
||||||
|
self.reconnection_function_active = False
|
||||||
|
|
||||||
def get_configuration(self):
|
def get_configuration(self):
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ class Session(object):
|
|||||||
@_require_configuration
|
@_require_configuration
|
||||||
def login(self):
|
def login(self):
|
||||||
|
|
||||||
""" Login into twitter using credentials from settings.
|
""" Login in to twitter using credentials from settings.
|
||||||
if the user account isn't authorised, it needs to call self.authorise() before login."""
|
if the user account isn't authorised, it needs to call self.authorise() before login."""
|
||||||
|
|
||||||
if self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None:
|
if self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None:
|
||||||
@ -257,12 +258,34 @@ 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."""
|
||||||
|
self.get_main_stream()
|
||||||
|
self.get_timelines()
|
||||||
|
|
||||||
|
def get_main_stream(self):
|
||||||
self.main_stream = twitter.buffers.stream.streamer(application.app_key, application.app_secret, self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], self)
|
self.main_stream = twitter.buffers.stream.streamer(application.app_key, application.app_secret, self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], self)
|
||||||
call_threaded(self.main_stream.user)
|
stream_threaded(self.main_stream.user, self.session_id)
|
||||||
|
|
||||||
|
def get_timelines(self):
|
||||||
self.timelinesStream = twitter.buffers.indibidual.timelinesStreamer(application.app_key, application.app_secret, self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], session=self)
|
self.timelinesStream = twitter.buffers.indibidual.timelinesStreamer(application.app_key, application.app_secret, self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"], session=self)
|
||||||
ids = ""
|
ids = ""
|
||||||
for i in self.settings["other_buffers"]["timelines"]:
|
for i in self.settings["other_buffers"]["timelines"]:
|
||||||
ids = ids + "%s, " % (self.db[i+"-timeline"][0]["user"]["id_str"])
|
ids = ids + "%s, " % (self.db[i+"-timeline"][0]["user"]["id_str"])
|
||||||
# if ids != "":
|
# if ids != "":
|
||||||
call_threaded(self.timelinesStream.statuses.filter, follow=ids)
|
stream_threaded(self.timelinesStream.statuses.filter, self.session_id, follow=ids)
|
||||||
|
|
||||||
|
def listen_stream_error(self):
|
||||||
|
if hasattr(self, "main_stream"):
|
||||||
|
self.main_stream.disconnect()
|
||||||
|
del self.main_stream
|
||||||
|
if hasattr(self, "timelinesStream"):
|
||||||
|
self.timelinesStream.disconnect()
|
||||||
|
del self.timelinesStream
|
||||||
|
|
||||||
|
def check_connection(self):
|
||||||
|
if self.reconnection_function_active == True: return
|
||||||
|
self.reconnection_function_active = True
|
||||||
|
if not hasattr(self, "main_stream"):
|
||||||
|
self.get_main_stream()
|
||||||
|
if not hasattr(self, "timelinesStream"):
|
||||||
|
self.get_timelines()
|
||||||
|
self.reconnection_function_active = False
|
||||||
|
@ -74,7 +74,6 @@ class streamer(TwythonStreamer):
|
|||||||
def remove_fav(self, data):
|
def remove_fav(self, data):
|
||||||
if self.session.db["user_name"] == data["source"]["screen_name"]:
|
if self.session.db["user_name"] == data["source"]["screen_name"]:
|
||||||
item = utils.find_item(data["target_object"]["id"], self.session.db["favourites"])
|
item = utils.find_item(data["target_object"]["id"], self.session.db["favourites"])
|
||||||
print item
|
|
||||||
self.session.db["favourites"].pop(item)
|
self.session.db["favourites"].pop(item)
|
||||||
pub.sendMessage("unfavourite", item=item, user=self.get_user())
|
pub.sendMessage("unfavourite", item=item, user=self.get_user())
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ class viewTweet(widgetUtils.BaseDialog):
|
|||||||
self.SetClientSize(mainBox.CalcMin())
|
self.SetClientSize(mainBox.CalcMin())
|
||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
self.text.ChangeValue()
|
self.text.ChangeValue(text)
|
||||||
|
|
||||||
def get_text(self):
|
def get_text(self):
|
||||||
return self.text.GetValue()
|
return self.text.GetValue()
|
||||||
@ -264,7 +264,7 @@ class viewNonTweet(widgetUtils.BaseDialog):
|
|||||||
self.text.SelectAll()
|
self.text.SelectAll()
|
||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
self.text.ChangeValue()
|
self.text.ChangeValue(text)
|
||||||
|
|
||||||
def get_text(self):
|
def get_text(self):
|
||||||
return self.text.GetValue()
|
return self.text.GetValue()
|
||||||
|
Loading…
Reference in New Issue
Block a user