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)
|
||||
if message.message.get_response() == widgetUtils.OK:
|
||||
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:
|
||||
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):
|
||||
tweet = self.get_tweet()
|
||||
|
@ -2,7 +2,7 @@
|
||||
from wxUI import (view, dialogs, commonMessageDialogs)
|
||||
import buffersController
|
||||
import messages
|
||||
from sessionmanager import session
|
||||
from sessionmanager import session as session_
|
||||
from pubsub import pub
|
||||
import sound
|
||||
import output
|
||||
@ -13,9 +13,12 @@ import config
|
||||
import widgetUtils
|
||||
import platform
|
||||
from extra import SoundsTutorial
|
||||
import logging
|
||||
if platform.system() == "Windows":
|
||||
import keystrokeEditor
|
||||
|
||||
log = logging.getLogger("mainController")
|
||||
|
||||
class Controller(object):
|
||||
|
||||
""" Main Controller for TWBlue. It manages the main window and sessions."""
|
||||
@ -65,6 +68,7 @@ class Controller(object):
|
||||
|
||||
def bind_other_events(self):
|
||||
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.learn_sounds, menuitem=self.view.sounds_tutorial)
|
||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.exit, menuitem=self.view.close)
|
||||
@ -87,10 +91,14 @@ class Controller(object):
|
||||
self.do_work()
|
||||
|
||||
def do_work(self):
|
||||
for i in session.sessions:
|
||||
self.create_buffers(session.sessions[i])
|
||||
call_threaded(self.start_buffers, session.sessions[i])
|
||||
log.debug("Creating buffers for all sessions...")
|
||||
for i in session_.sessions:
|
||||
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")
|
||||
self.checker_function = RepeatingTimer(60, self.check_connection)
|
||||
self.checker_function.start()
|
||||
|
||||
def create_buffers(self, session):
|
||||
session.get_user_info()
|
||||
@ -222,10 +230,10 @@ class Controller(object):
|
||||
buffer.destroy_status()
|
||||
|
||||
def exit(self, *args, **kwargs):
|
||||
for item in session.sessions:
|
||||
session.sessions[item].settings.write()
|
||||
session.sessions[item].main_stream.disconnect()
|
||||
session.sessions[item].timelinesStream.disconnect()
|
||||
for item in session_.sessions:
|
||||
session_.sessions[item].settings.write()
|
||||
session_.sessions[item].main_stream.disconnect()
|
||||
session_.sessions[item].timelinesStream.disconnect()
|
||||
sound.player.cleaner.cancel()
|
||||
widgetUtils.exit_application()
|
||||
|
||||
@ -396,10 +404,22 @@ class Controller(object):
|
||||
print "i've pressed"
|
||||
|
||||
def start_buffers(self, session):
|
||||
log.debug("starting buffers... Session %s" % (session,))
|
||||
for i in self.buffers:
|
||||
log.debug("Starting %s for %s" % (i.name, session))
|
||||
if i.session == session and i.needs_init == True:
|
||||
i.start_stream()
|
||||
log.debug("Starting the streaming endpoint")
|
||||
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):
|
||||
config.app.write()
|
@ -6,8 +6,8 @@ import sys
|
||||
|
||||
APP_LOG_FILE = 'debug.log'
|
||||
ERROR_LOG_FILE = "error.log"
|
||||
MESSAGE_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s"
|
||||
DATE_FORMAT = "%a %b %d, %Y %H:%M:%S"
|
||||
MESSAGE_FORMAT = u"%(asctime)s %(name)s %(levelname)s: %(message)s"
|
||||
DATE_FORMAT = u"%b %d, %Y %H:%M:%S"
|
||||
|
||||
formatter = logging.Formatter(MESSAGE_FORMAT, datefmt=DATE_FORMAT)
|
||||
|
||||
|
@ -6,6 +6,7 @@ import commandline
|
||||
import config
|
||||
import sound
|
||||
import output
|
||||
from logger import logger as logging
|
||||
|
||||
def setup():
|
||||
config.setup()
|
||||
|
@ -11,9 +11,7 @@ def call_threaded(func, *args, **kwargs):
|
||||
try:
|
||||
func(*a, **k)
|
||||
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()
|
||||
time.sleep(300)
|
||||
call_threaded(func, *args, **kwargs)
|
||||
pass
|
||||
# except:
|
||||
# pass
|
||||
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 new_func(*a, **k):
|
||||
# global session
|
||||
try:
|
||||
func(*a, **k)
|
||||
func(**k)
|
||||
except:
|
||||
pub.sendMessage("streamError")
|
||||
pub.sendMessage("streamError", session=a[0])
|
||||
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
@ -10,7 +10,7 @@ import sound
|
||||
from twitter import utils
|
||||
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
||||
from config_utils import Configuration, ConfigurationResetException
|
||||
from mysc.thread_utils import call_threaded
|
||||
from mysc.thread_utils import stream_threaded
|
||||
|
||||
sessions = {}
|
||||
|
||||
@ -88,6 +88,7 @@ class Session(object):
|
||||
self.settings = None
|
||||
self.twitter = twitter.twitter.twitter()
|
||||
self.db = {}
|
||||
self.reconnection_function_active = False
|
||||
|
||||
def get_configuration(self):
|
||||
|
||||
@ -257,12 +258,34 @@ class Session(object):
|
||||
def start_streaming(self):
|
||||
|
||||
""" 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)
|
||||
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)
|
||||
ids = ""
|
||||
for i in self.settings["other_buffers"]["timelines"]:
|
||||
ids = ids + "%s, " % (self.db[i+"-timeline"][0]["user"]["id_str"])
|
||||
# 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):
|
||||
if self.session.db["user_name"] == data["source"]["screen_name"]:
|
||||
item = utils.find_item(data["target_object"]["id"], self.session.db["favourites"])
|
||||
print item
|
||||
self.session.db["favourites"].pop(item)
|
||||
pub.sendMessage("unfavourite", item=item, user=self.get_user())
|
||||
|
||||
|
@ -210,7 +210,7 @@ class viewTweet(widgetUtils.BaseDialog):
|
||||
self.SetClientSize(mainBox.CalcMin())
|
||||
|
||||
def set_text(self, text):
|
||||
self.text.ChangeValue()
|
||||
self.text.ChangeValue(text)
|
||||
|
||||
def get_text(self):
|
||||
return self.text.GetValue()
|
||||
@ -264,7 +264,7 @@ class viewNonTweet(widgetUtils.BaseDialog):
|
||||
self.text.SelectAll()
|
||||
|
||||
def set_text(self, text):
|
||||
self.text.ChangeValue()
|
||||
self.text.ChangeValue(text)
|
||||
|
||||
def get_text(self):
|
||||
return self.text.GetValue()
|
||||
|
Loading…
Reference in New Issue
Block a user