mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-23 03:38:08 -06:00
Initial support for extended tweets
This commit is contained in:
parent
b131f50d42
commit
df345b5eec
@ -224,7 +224,7 @@ class emptyPanel(bufferController):
|
|||||||
self.needs_init = True
|
self.needs_init = True
|
||||||
|
|
||||||
class baseBufferController(bufferController):
|
class baseBufferController(bufferController):
|
||||||
def __init__(self, parent, function, name, sessionObject, account, sound=None, bufferType=None, *args, **kwargs):
|
def __init__(self, parent, function, name, sessionObject, account, sound=None, bufferType=None, compose_func="compose_tweet", *args, **kwargs):
|
||||||
super(baseBufferController, self).__init__(parent, function, *args, **kwargs)
|
super(baseBufferController, self).__init__(parent, function, *args, **kwargs)
|
||||||
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
log.debug("Initializing buffer %s, account %s" % (name, account,))
|
||||||
if bufferType != None:
|
if bufferType != None:
|
||||||
@ -235,7 +235,7 @@ class baseBufferController(bufferController):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.type = self.buffer.type
|
self.type = self.buffer.type
|
||||||
self.session = sessionObject
|
self.session = sessionObject
|
||||||
self.compose_function = compose.compose_tweet
|
self.compose_function = getattr(compose, compose_func)
|
||||||
log.debug("Compose_function: %s" % (self.compose_function,))
|
log.debug("Compose_function: %s" % (self.compose_function,))
|
||||||
self.account = account
|
self.account = account
|
||||||
self.buffer.account = account
|
self.buffer.account = account
|
||||||
@ -258,10 +258,10 @@ class baseBufferController(bufferController):
|
|||||||
if tweet.has_key("message"):
|
if tweet.has_key("message"):
|
||||||
message = tweet["message"]
|
message = tweet["message"]
|
||||||
try:
|
try:
|
||||||
tweet = self.session.twitter.twitter.show_status(id=tweet_id, include_ext_alt_text=True)
|
tweet = self.session.twitter.twitter.show_status(id=tweet_id, include_ext_alt_text=True, tweet_mode="extended")
|
||||||
urls = utils.find_urls_in_text(tweet["text"])
|
urls = utils.find_urls_in_text(tweet["full_text"])
|
||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
try: tweet["full_text"] = tweet["full_text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
except TwythonError as e:
|
except TwythonError as e:
|
||||||
utils.twitter_error(e)
|
utils.twitter_error(e)
|
||||||
@ -272,10 +272,10 @@ class baseBufferController(bufferController):
|
|||||||
while l != False:
|
while l != False:
|
||||||
tweetsList.append(tweet)
|
tweetsList.append(tweet)
|
||||||
try:
|
try:
|
||||||
tweet = self.session.twitter.twitter.show_status(id=l, include_ext_alt_text=True)
|
tweet = self.session.twitter.twitter.show_status(id=l, include_ext_alt_text=True, tweet_mode="extended")
|
||||||
urls = utils.find_urls_in_text(tweet["text"])
|
urls = utils.find_urls_in_text(tweet["full_text"])
|
||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
try: tweet["full_text"] = tweet["full_text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
except TwythonError as e:
|
except TwythonError as e:
|
||||||
utils.twitter_error(e)
|
utils.twitter_error(e)
|
||||||
@ -479,8 +479,8 @@ class baseBufferController(bufferController):
|
|||||||
tweet = self.get_right_tweet()
|
tweet = self.get_right_tweet()
|
||||||
screen_name = tweet["user"]["screen_name"]
|
screen_name = tweet["user"]["screen_name"]
|
||||||
id = tweet["id"]
|
id = tweet["id"]
|
||||||
users = utils.get_all_mentioned(tweet, self.session.db)
|
users = len(utils.get_all_mentioned(tweet, self.session.db))
|
||||||
message = messages.reply(self.session, _(u"Reply"), _(u"Reply to %s") % (screen_name,), "@%s " % (screen_name,), twishort_enabled=self.session.settings["mysc"]["twishort_enabled"], users=users)
|
message = messages.reply(self.session, _(u"Reply"), _(u"Reply to %s") % (screen_name,), "", twishort_enabled=self.session.settings["mysc"]["twishort_enabled"], users=users)
|
||||||
if message.message.get_response() == widgetUtils.OK:
|
if message.message.get_response() == widgetUtils.OK:
|
||||||
self.session.settings["mysc"]["twishort_enabled"] = message.message.long_tweet.GetValue()
|
self.session.settings["mysc"]["twishort_enabled"] = message.message.long_tweet.GetValue()
|
||||||
text = message.message.get_text()
|
text = message.message.get_text()
|
||||||
@ -490,9 +490,9 @@ class baseBufferController(bufferController):
|
|||||||
else:
|
else:
|
||||||
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1)
|
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1)
|
||||||
if message.image == None:
|
if message.image == None:
|
||||||
call_threaded(self.session.api_call, call_name="update_status", _sound="reply_send.ogg", in_reply_to_status_id=id, status=text)
|
call_threaded(self.session.api_call, call_name="update_status", _sound="reply_send.ogg", in_reply_to_status_id=id, status=text, auto_populate_reply_metadata=message.message.mentionAll.GetValue())
|
||||||
else:
|
else:
|
||||||
call_threaded(self.session.api_call, call_name="update_status_with_media", _sound="reply_send.ogg", in_reply_to_status_id=id, status=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=text, media=message.file, auto_populate_reply_metadata=message.message.mentionAll.GetValue())
|
||||||
if hasattr(message.message, "destroy"): message.message.destroy()
|
if hasattr(message.message, "destroy"): message.message.destroy()
|
||||||
|
|
||||||
@_tweets_exist
|
@_tweets_exist
|
||||||
@ -534,14 +534,14 @@ class baseBufferController(bufferController):
|
|||||||
self._retweet_with_comment(tweet, id)
|
self._retweet_with_comment(tweet, id)
|
||||||
|
|
||||||
def _retweet_with_comment(self, tweet, id, comment=''):
|
def _retweet_with_comment(self, tweet, id, comment=''):
|
||||||
retweet = messages.tweet(self.session, _(u"Retweet"), _(u"Add your comment to the tweet"), u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["text"]), max=116, messageType="retweet", twishort_enabled=self.session.settings["mysc"]["twishort_enabled"])
|
retweet = messages.tweet(self.session, _(u"Retweet"), _(u"Add your comment to the tweet"), u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["full_text"]), max=116, messageType="retweet", twishort_enabled=self.session.settings["mysc"]["twishort_enabled"])
|
||||||
if comment != '':
|
if comment != '':
|
||||||
retweet.message.set_text(comment)
|
retweet.message.set_text(comment)
|
||||||
if retweet.message.get_response() == widgetUtils.OK:
|
if retweet.message.get_response() == widgetUtils.OK:
|
||||||
text = retweet.message.get_text()
|
text = retweet.message.get_text()
|
||||||
comments=text
|
comments=text
|
||||||
if len(text+ u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["text"])) < 140:
|
if len(text+ u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["full_text"])) < 140:
|
||||||
text = text+u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["text"])
|
text = text+u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["full_text"])
|
||||||
else:
|
else:
|
||||||
answer = commonMessageDialogs.retweet_as_link(self.buffer)
|
answer = commonMessageDialogs.retweet_as_link(self.buffer)
|
||||||
if answer == widgetUtils.YES:
|
if answer == widgetUtils.YES:
|
||||||
@ -1100,7 +1100,7 @@ class conversationBufferController(searchBufferController):
|
|||||||
tweet = self.tweet
|
tweet = self.tweet
|
||||||
while tweet["in_reply_to_status_id"] != None:
|
while tweet["in_reply_to_status_id"] != None:
|
||||||
try:
|
try:
|
||||||
tweet = self.session.twitter.twitter.show_status(id=tweet["in_reply_to_status_id"])
|
tweet = self.session.twitter.twitter.show_status(id=tweet["in_reply_to_status_id"], tweet_mode="extended")
|
||||||
except TwythonError as err:
|
except TwythonError as err:
|
||||||
break
|
break
|
||||||
self.statuses.insert(0, tweet)
|
self.statuses.insert(0, tweet)
|
||||||
@ -1108,7 +1108,7 @@ class conversationBufferController(searchBufferController):
|
|||||||
if tweet["in_reply_to_status_id"] == None:
|
if tweet["in_reply_to_status_id"] == None:
|
||||||
self.kwargs["since_id"] = tweet["id"]
|
self.kwargs["since_id"] = tweet["id"]
|
||||||
self.ids.append(tweet["id"])
|
self.ids.append(tweet["id"])
|
||||||
val2 = self.session.search(self.name, *self.args, **self.kwargs)
|
val2 = self.session.search(self.name, tweet_mode="extended", *self.args, **self.kwargs)
|
||||||
for i in val2:
|
for i in val2:
|
||||||
if i["in_reply_to_status_id"] in self.ids:
|
if i["in_reply_to_status_id"] in self.ids:
|
||||||
self.statuses.append(i)
|
self.statuses.append(i)
|
||||||
@ -1128,12 +1128,3 @@ class conversationBufferController(searchBufferController):
|
|||||||
return True
|
return True
|
||||||
elif dlg == widgetUtils.NO:
|
elif dlg == widgetUtils.NO:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class pocketBufferController(baseBufferController):
|
|
||||||
def __init__(self, parent, name, sessionObject, account, sound=None, function=None, bufferType=None, *args, **kwargs):
|
|
||||||
super(pocketBufferController, self).__init__(parent, name, sessionObject, account, sound, function, bufferType, *args, **kwargs)
|
|
||||||
self.type = "pocket"
|
|
||||||
|
|
||||||
def start_stream(self):
|
|
||||||
log.debug("Starting stream for buffer %s, account %s and type %s" % (self.name, self.account, self.type))
|
|
||||||
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))
|
|
||||||
|
@ -293,27 +293,27 @@ class Controller(object):
|
|||||||
self.view.add_buffer(account.buffer , name=session.db["user_name"])
|
self.view.add_buffer(account.buffer , name=session.db["user_name"])
|
||||||
for i in session.settings['general']['buffer_order']:
|
for i in session.settings['general']['buffer_order']:
|
||||||
if i == 'home':
|
if i == 'home':
|
||||||
home = buffersController.baseBufferController(self.view.nb, "get_home_timeline", "home_timeline", session, session.db["user_name"])
|
home = buffersController.baseBufferController(self.view.nb, "get_home_timeline", "home_timeline", session, session.db["user_name"], tweet_mode="extended")
|
||||||
self.buffers.append(home)
|
self.buffers.append(home)
|
||||||
self.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
elif i == 'mentions':
|
elif i == 'mentions':
|
||||||
mentions = buffersController.baseBufferController(self.view.nb, "get_mentions_timeline", "mentions", session, session.db["user_name"], sound="mention_received.ogg")
|
mentions = buffersController.baseBufferController(self.view.nb, "get_mentions_timeline", "mentions", session, session.db["user_name"], sound="mention_received.ogg", tweet_mode="extended")
|
||||||
self.buffers.append(mentions)
|
self.buffers.append(mentions)
|
||||||
self.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
elif i == 'dm':
|
elif i == 'dm':
|
||||||
dm = buffersController.baseBufferController(self.view.nb, "get_direct_messages", "direct_messages", session, session.db["user_name"], bufferType="dmPanel", sound="dm_received.ogg", full_text=True)
|
dm = buffersController.baseBufferController(self.view.nb, "get_direct_messages", "direct_messages", session, session.db["user_name"], bufferType="dmPanel", compose_func="compose_dm", sound="dm_received.ogg", full_text=True)
|
||||||
self.buffers.append(dm)
|
self.buffers.append(dm)
|
||||||
self.view.insert_buffer(dm.buffer, name=_(u"Direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(dm.buffer, name=_(u"Direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
elif i == 'sent_dm':
|
elif i == 'sent_dm':
|
||||||
sent_dm = buffersController.baseBufferController(self.view.nb, "get_sent_messages", "sent_direct_messages", session, session.db["user_name"], bufferType="dmPanel", full_text=True)
|
sent_dm = buffersController.baseBufferController(self.view.nb, "get_sent_messages", "sent_direct_messages", session, session.db["user_name"], bufferType="dmPanel", compose_func="compose_dm", full_text=True)
|
||||||
self.buffers.append(sent_dm)
|
self.buffers.append(sent_dm)
|
||||||
self.view.insert_buffer(sent_dm.buffer, name=_(u"Sent direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(sent_dm.buffer, name=_(u"Sent direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
elif i == 'sent_tweets':
|
elif i == 'sent_tweets':
|
||||||
sent_tweets = buffersController.baseBufferController(self.view.nb, "get_user_timeline", "sent_tweets", session, session.db["user_name"], bufferType="dmPanel", screen_name=session.db["user_name"])
|
sent_tweets = buffersController.baseBufferController(self.view.nb, "get_user_timeline", "sent_tweets", session, session.db["user_name"], bufferType="dmPanel", screen_name=session.db["user_name"], tweet_mode="extended")
|
||||||
self.buffers.append(sent_tweets)
|
self.buffers.append(sent_tweets)
|
||||||
self.view.insert_buffer(sent_tweets.buffer, name=_(u"Sent tweets"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(sent_tweets.buffer, name=_(u"Sent tweets"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
elif i == 'favorites':
|
elif i == 'favorites':
|
||||||
favourites = buffersController.baseBufferController(self.view.nb, "get_favorites", "favourites", session, session.db["user_name"])
|
favourites = buffersController.baseBufferController(self.view.nb, "get_favorites", "favourites", session, session.db["user_name"], tweet_mode="extended")
|
||||||
self.buffers.append(favourites)
|
self.buffers.append(favourites)
|
||||||
|
|
||||||
self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
@ -341,14 +341,14 @@ class Controller(object):
|
|||||||
self.buffers.append(timelines)
|
self.buffers.append(timelines)
|
||||||
self.view.insert_buffer(timelines.buffer , name=_(u"Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(timelines.buffer , name=_(u"Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
for i in session.settings["other_buffers"]["timelines"]:
|
for i in session.settings["other_buffers"]["timelines"]:
|
||||||
tl = buffersController.baseBufferController(self.view.nb, "get_user_timeline", "%s-timeline" % (i,), session, session.db["user_name"], bufferType=None, screen_name=i)
|
tl = buffersController.baseBufferController(self.view.nb, "get_user_timeline", "%s-timeline" % (i,), session, session.db["user_name"], bufferType=None, screen_name=i, tweet_mode="extended")
|
||||||
self.buffers.append(tl)
|
self.buffers.append(tl)
|
||||||
self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(i,), pos=self.view.search("timelines", session.db["user_name"]))
|
self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(i,), pos=self.view.search("timelines", session.db["user_name"]))
|
||||||
favs_timelines = buffersController.emptyPanel(self.view.nb, "favs_timelines", session.db["user_name"])
|
favs_timelines = buffersController.emptyPanel(self.view.nb, "favs_timelines", session.db["user_name"])
|
||||||
self.buffers.append(favs_timelines)
|
self.buffers.append(favs_timelines)
|
||||||
self.view.insert_buffer(favs_timelines.buffer , name=_(u"Likes timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(favs_timelines.buffer , name=_(u"Likes timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
for i in session.settings["other_buffers"]["favourites_timelines"]:
|
for i in session.settings["other_buffers"]["favourites_timelines"]:
|
||||||
tl = buffersController.baseBufferController(self.view.nb, "get_favorites", "%s-favorite" % (i,), session, session.db["user_name"], bufferType=None, screen_name=i)
|
tl = buffersController.baseBufferController(self.view.nb, "get_favorites", "%s-favorite" % (i,), session, session.db["user_name"], bufferType=None, screen_name=i, tweet_mode="extended")
|
||||||
self.buffers.append(tl)
|
self.buffers.append(tl)
|
||||||
self.view.insert_buffer(tl.buffer, name=_(u"Likes for {}").format(i,), pos=self.view.search("favs_timelines", session.db["user_name"]))
|
self.view.insert_buffer(tl.buffer, name=_(u"Likes for {}").format(i,), pos=self.view.search("favs_timelines", session.db["user_name"]))
|
||||||
tl.timer = RepeatingTimer(300, tl.start_stream)
|
tl.timer = RepeatingTimer(300, tl.start_stream)
|
||||||
@ -375,7 +375,7 @@ class Controller(object):
|
|||||||
self.buffers.append(lists)
|
self.buffers.append(lists)
|
||||||
self.view.insert_buffer(lists.buffer , name=_(u"Lists"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(lists.buffer , name=_(u"Lists"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
for i in session.settings["other_buffers"]["lists"]:
|
for i in session.settings["other_buffers"]["lists"]:
|
||||||
tl = buffersController.listBufferController(self.view.nb, "get_list_statuses", "%s-list" % (i,), session, session.db["user_name"], bufferType=None, list_id=utils.find_list(i, session.db["lists"]))
|
tl = buffersController.listBufferController(self.view.nb, "get_list_statuses", "%s-list" % (i,), session, session.db["user_name"], bufferType=None, list_id=utils.find_list(i, session.db["lists"]), tweet_mode="extended")
|
||||||
session.lists.append(tl)
|
session.lists.append(tl)
|
||||||
self.buffers.append(tl)
|
self.buffers.append(tl)
|
||||||
self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(i), pos=self.view.search("lists", session.db["user_name"]))
|
self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(i), pos=self.view.search("lists", session.db["user_name"]))
|
||||||
@ -383,7 +383,7 @@ class Controller(object):
|
|||||||
self.buffers.append(searches)
|
self.buffers.append(searches)
|
||||||
self.view.insert_buffer(searches.buffer , name=_(u"Searches"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
self.view.insert_buffer(searches.buffer , name=_(u"Searches"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
|
||||||
for i in session.settings["other_buffers"]["tweet_searches"]:
|
for i in session.settings["other_buffers"]["tweet_searches"]:
|
||||||
tl = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (i,), session, session.db["user_name"], bufferType="searchPanel", q=i, count=session.settings["general"]["max_tweets_per_call"])
|
tl = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (i,), session, session.db["user_name"], bufferType="searchPanel", q=i, count=session.settings["general"]["max_tweets_per_call"], tweet_mode="extended")
|
||||||
self.buffers.append(tl)
|
self.buffers.append(tl)
|
||||||
self.view.insert_buffer(tl.buffer, name=_(u"Search for {}").format(i), pos=self.view.search("searches", session.db["user_name"]))
|
self.view.insert_buffer(tl.buffer, name=_(u"Search for {}").format(i), pos=self.view.search("searches", session.db["user_name"]))
|
||||||
tl.timer = RepeatingTimer(180, tl.start_stream)
|
tl.timer = RepeatingTimer(180, tl.start_stream)
|
||||||
|
@ -147,10 +147,11 @@ class tweet(basicTweet):
|
|||||||
class reply(tweet):
|
class reply(tweet):
|
||||||
def __init__(self, session, title, caption, text, twishort_enabled, users=None):
|
def __init__(self, session, title, caption, text, twishort_enabled, users=None):
|
||||||
super(reply, self).__init__(session, title, caption, text, twishort_enabled, messageType="reply")
|
super(reply, self).__init__(session, title, caption, text, twishort_enabled, messageType="reply")
|
||||||
self.users = users
|
self.message.mentionAll.SetValue(True)
|
||||||
if self.users != None and len(self.users) > 1:
|
if users > 1:
|
||||||
widgetUtils.connect_event(self.message.mentionAll, widgetUtils.BUTTON_PRESSED, self.mention_all)
|
# widgetUtils.connect_event(self.message.mentionAll, widgetUtils.CHECKBOX, self.mention_all)
|
||||||
self.message.enable_button("mentionAll")
|
self.message.enable_button("mentionAll")
|
||||||
|
self.message.mentionAll.SetValue(False)
|
||||||
self.message.set_cursor_at_end()
|
self.message.set_cursor_at_end()
|
||||||
self.text_processor()
|
self.text_processor()
|
||||||
|
|
||||||
@ -184,10 +185,10 @@ class viewTweet(basicTweet):
|
|||||||
if tweetList[i].has_key("message") and tweetList[i]["is_quote_status"] == False:
|
if tweetList[i].has_key("message") and tweetList[i]["is_quote_status"] == False:
|
||||||
value = "message"
|
value = "message"
|
||||||
else:
|
else:
|
||||||
value = "text"
|
value = "full_text"
|
||||||
if tweetList[i].has_key("retweeted_status") and tweetList[i]["is_quote_status"] == False:
|
if tweetList[i].has_key("retweeted_status") and tweetList[i]["is_quote_status"] == False:
|
||||||
if tweetList[i].has_key("message") == False:
|
if tweetList[i].has_key("message") == False:
|
||||||
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["text"])
|
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["full_text"])
|
||||||
else:
|
else:
|
||||||
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value])
|
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value])
|
||||||
else:
|
else:
|
||||||
@ -206,10 +207,10 @@ class viewTweet(basicTweet):
|
|||||||
if tweet.has_key("message"):
|
if tweet.has_key("message"):
|
||||||
value = "message"
|
value = "message"
|
||||||
else:
|
else:
|
||||||
value = "text"
|
value = "full_text"
|
||||||
if tweet.has_key("retweeted_status"):
|
if tweet.has_key("retweeted_status"):
|
||||||
if tweet.has_key("message") == False:
|
if tweet.has_key("message") == False:
|
||||||
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet["retweeted_status"]["text"])
|
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet["retweeted_status"]["full_text"])
|
||||||
else:
|
else:
|
||||||
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value])
|
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value])
|
||||||
else:
|
else:
|
||||||
|
@ -24,7 +24,7 @@ def is_long(tweet):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def clear_url(tweet):
|
def clear_url(tweet):
|
||||||
urls = utils.find_urls_in_text(tweet["text"])
|
urls = utils.find_urls_in_text(tweet["full_text"])
|
||||||
try: tweet["message"] = tweet["message"].replace(urls[-1], "")
|
try: tweet["message"] = tweet["message"].replace(urls[-1], "")
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
return tweet
|
return tweet
|
@ -432,17 +432,17 @@ class Session(object):
|
|||||||
|
|
||||||
def get_quoted_tweet(self, tweet):
|
def get_quoted_tweet(self, tweet):
|
||||||
quoted_tweet = tweet
|
quoted_tweet = tweet
|
||||||
urls = utils.find_urls_in_text(quoted_tweet["text"])
|
urls = utils.find_urls_in_text(quoted_tweet["full_text"])
|
||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
try: quoted_tweet["text"] = quoted_tweet["text"].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
|
try: quoted_tweet["full_text"] = quoted_tweet["full_text"].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
id = tweets.is_long(quoted_tweet)
|
id = tweets.is_long(quoted_tweet)
|
||||||
try: original_tweet = self.twitter.twitter.show_status(id=id)
|
try: original_tweet = self.twitter.twitter.show_status(id=id, tweet_mode="extended")
|
||||||
except: return quoted_tweet
|
except: return quoted_tweet
|
||||||
original_tweet = self.check_long_tweet(original_tweet)
|
original_tweet = self.check_long_tweet(original_tweet)
|
||||||
urls = utils.find_urls_in_text(original_tweet["text"])
|
urls = utils.find_urls_in_text(original_tweet["full_text"])
|
||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
try: original_tweet["text"] = original_tweet["text"].replace(urls[url], original_tweet["entities"]["urls"][url]["expanded_url"])
|
try: original_tweet["full_text"] = original_tweet["full_text"].replace(urls[url], original_tweet["entities"]["urls"][url]["expanded_url"])
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
return compose.compose_quoted_tweet(quoted_tweet, original_tweet)
|
return compose.compose_quoted_tweet(quoted_tweet, original_tweet)
|
||||||
|
|
||||||
|
@ -67,8 +67,11 @@ class timelinesStreamer(TwythonStreamer):
|
|||||||
self.friends = friends
|
self.friends = friends
|
||||||
|
|
||||||
def on_success(self, data):
|
def on_success(self, data):
|
||||||
try:
|
# try:
|
||||||
if "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
if "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
||||||
self.check_tls(data)
|
if data.has_key("extended_tweet"):
|
||||||
except:
|
data["full_text"] = data["extended_tweet"]["full_text"]
|
||||||
pass
|
data["entities"] = data["extended_entities"]
|
||||||
|
self.check_tls(data)
|
||||||
|
# except:
|
||||||
|
# pass
|
||||||
|
@ -135,6 +135,10 @@ class streamer(TwythonStreamer):
|
|||||||
self.friends = data["friends"]
|
self.friends = data["friends"]
|
||||||
pub.sendMessage("friends-receibed")
|
pub.sendMessage("friends-receibed")
|
||||||
elif "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
elif "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
||||||
|
if data.has_key("extended_tweet"):
|
||||||
|
data["full_text"] = data["extended_tweet"]["full_text"]
|
||||||
|
data["entities"] = data["extended_entities"]
|
||||||
|
log.error("Extended tweet")
|
||||||
if data["user"]["id"] in self.muted_users: return
|
if data["user"]["id"] in self.muted_users: return
|
||||||
self.check_mentions(data)
|
self.check_mentions(data)
|
||||||
self.check_send(data)
|
self.check_send(data)
|
||||||
|
@ -40,24 +40,23 @@ def compose_tweet(tweet, db, relative_times):
|
|||||||
ts = tweet["created_at"]
|
ts = tweet["created_at"]
|
||||||
if tweet.has_key("message"):
|
if tweet.has_key("message"):
|
||||||
value = "message"
|
value = "message"
|
||||||
|
log.error(tweet["message"])
|
||||||
|
elif tweet.has_key("full_text"):
|
||||||
|
value = "full_text"
|
||||||
else:
|
else:
|
||||||
value = "text"
|
value = "text"
|
||||||
|
log.exception(tweet.keys())
|
||||||
text = StripChars(tweet[value])
|
text = StripChars(tweet[value])
|
||||||
if tweet.has_key("sender"):
|
user = tweet["user"]["name"]
|
||||||
source = "DM"
|
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
||||||
if db["user_name"] == tweet["sender"]["screen_name"]: user = _(u"Dm to %s ") % (tweet["recipient"]["name"],)
|
if tweet.has_key("retweeted_status"):
|
||||||
else: user = tweet["sender"]["name"]
|
if tweet.has_key("message") == False and tweet["retweeted_status"]["is_quote_status"] == False:
|
||||||
elif tweet.has_key("user"):
|
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"][value]))
|
||||||
user = tweet["user"]["name"]
|
elif tweet["retweeted_status"]["is_quote_status"]:
|
||||||
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
text = "%s" % (StripChars(tweet[value]))
|
||||||
if tweet.has_key("retweeted_status"):
|
else:
|
||||||
if tweet.has_key("message") == False and tweet["retweeted_status"]["is_quote_status"] == False:
|
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet[value]))
|
||||||
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"]["text"]))
|
if text[-1] in chars: text=text+"."
|
||||||
elif tweet["retweeted_status"]["is_quote_status"]:
|
|
||||||
text = "%s" % (StripChars(tweet[value]))
|
|
||||||
else:
|
|
||||||
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet[value]))
|
|
||||||
if text[-1] in chars: text=text+"."
|
|
||||||
if tweet.has_key("message") == False:
|
if tweet.has_key("message") == False:
|
||||||
urls = utils.find_urls_in_text(text)
|
urls = utils.find_urls_in_text(text)
|
||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
@ -67,20 +66,41 @@ def compose_tweet(tweet, db, relative_times):
|
|||||||
# return [user+", ", text, ts+", ", source]
|
# return [user+", ", text, ts+", ", source]
|
||||||
return [user+", ", text, ts+", ", source]
|
return [user+", ", text, ts+", ", source]
|
||||||
|
|
||||||
|
def compose_dm(tweet, db, relative_times):
|
||||||
|
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
|
||||||
|
if system == "Windows":
|
||||||
|
original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en")
|
||||||
|
if relative_times == True:
|
||||||
|
ts = original_date.humanize(locale=languageHandler.getLanguage())
|
||||||
|
else:
|
||||||
|
ts = original_date.replace(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage())
|
||||||
|
else:
|
||||||
|
ts = tweet["created_at"]
|
||||||
|
text = StripChars(tweet["text"])
|
||||||
|
source = "DM"
|
||||||
|
if db["user_name"] == tweet["sender"]["screen_name"]: user = _(u"Dm to %s ") % (tweet["recipient"]["name"],)
|
||||||
|
else: user = tweet["sender"]["name"]
|
||||||
|
if text[-1] in chars: text=text+"."
|
||||||
|
urls = utils.find_urls_in_text(text)
|
||||||
|
for url in range(0, len(urls)):
|
||||||
|
try: text = text.replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
||||||
|
except IndexError: pass
|
||||||
|
return [user+", ", text, ts+", ", source]
|
||||||
|
|
||||||
def compose_quoted_tweet(quoted_tweet, original_tweet):
|
def compose_quoted_tweet(quoted_tweet, original_tweet):
|
||||||
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
|
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
|
||||||
text = StripChars(quoted_tweet["text"])
|
text = StripChars(quoted_tweet["full_text"])
|
||||||
quoting_user = quoted_tweet["user"]["name"]
|
quoting_user = quoted_tweet["user"]["name"]
|
||||||
source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"])
|
source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"])
|
||||||
try: text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], StripChars(quoted_tweet["retweeted_status"]["text"]))
|
try: text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], StripChars(quoted_tweet["retweeted_status"]["full_text"]))
|
||||||
except KeyError: text = "%s" % (StripChars(quoted_tweet["text"]))
|
except KeyError: text = "%s" % (StripChars(quoted_tweet["full_text"]))
|
||||||
if text[-1] in chars: text=text+"."
|
if text[-1] in chars: text=text+"."
|
||||||
original_user = original_tweet["user"]["screen_name"]
|
original_user = original_tweet["user"]["screen_name"]
|
||||||
if original_tweet.has_key("message"):
|
if original_tweet.has_key("message"):
|
||||||
original_text = StripChars(original_tweet["message"])
|
original_text = StripChars(original_tweet["message"])
|
||||||
else:
|
else:
|
||||||
original_text = StripChars(original_tweet["text"])
|
original_text = StripChars(original_tweet["full_text"])
|
||||||
quoted_tweet["message"] = _(u"{0}. Quoted tweet from @{1}: {2}").format( quoted_tweet["text"], original_user, original_text)
|
quoted_tweet["message"] = _(u"{0}. Quoted tweet from @{1}: {2}").format( quoted_tweet["full_text"], original_user, original_text)
|
||||||
quoted_tweet = tweets.clear_url(quoted_tweet)
|
quoted_tweet = tweets.clear_url(quoted_tweet)
|
||||||
return quoted_tweet
|
return quoted_tweet
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ def find_urls (tweet):
|
|||||||
urls = []
|
urls = []
|
||||||
if tweet.has_key("message"):
|
if tweet.has_key("message"):
|
||||||
i = "message"
|
i = "message"
|
||||||
|
elif tweet.has_key("full_text"):
|
||||||
|
i = "full_text"
|
||||||
else:
|
else:
|
||||||
i = "text"
|
i = "text"
|
||||||
return [s[0] for s in url_re.findall(tweet[i])]
|
return [s[0] for s in url_re.findall(tweet[i])]
|
||||||
@ -57,6 +59,7 @@ def is_audio(tweet):
|
|||||||
if i["text"] == "audio":
|
if i["text"] == "audio":
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
|
print tweet["entities"]["hashtags"]
|
||||||
log.exception("Exception while executing is_audio hashtag algorithm")
|
log.exception("Exception while executing is_audio hashtag algorithm")
|
||||||
|
|
||||||
def is_geocoded(tweet):
|
def is_geocoded(tweet):
|
||||||
@ -120,7 +123,7 @@ def is_allowed(tweet, clients):
|
|||||||
for i in clients:
|
for i in clients:
|
||||||
if i.lower() == source.lower():
|
if i.lower() == source.lower():
|
||||||
allowed = False
|
allowed = False
|
||||||
log.exception("Tuit not allowed: %s" % (tweet["text"],))
|
# log.exception("Tuit not allowed: %r" % (tweet,))
|
||||||
return allowed
|
return allowed
|
||||||
|
|
||||||
def twitter_error(error):
|
def twitter_error(error):
|
||||||
|
@ -234,7 +234,7 @@ class reply(tweet):
|
|||||||
def __init__(self, title, message, text):
|
def __init__(self, title, message, text):
|
||||||
super(reply, self).__init__(message, title, text)
|
super(reply, self).__init__(message, title, text)
|
||||||
self.text.SetInsertionPoint(len(self.text.GetValue()))
|
self.text.SetInsertionPoint(len(self.text.GetValue()))
|
||||||
self.mentionAll = wx.Button(self, -1, _(u"&Mention to all"), size=wx.DefaultSize)
|
self.mentionAll = wx.CheckBox(self, -1, _(u"&Mention to all"), size=wx.DefaultSize)
|
||||||
self.mentionAll.Disable()
|
self.mentionAll.Disable()
|
||||||
self.buttonsBox1.Add(self.mentionAll, 0, wx.ALL, 5)
|
self.buttonsBox1.Add(self.mentionAll, 0, wx.ALL, 5)
|
||||||
self.buttonsBox1.Layout()
|
self.buttonsBox1.Layout()
|
||||||
|
Loading…
Reference in New Issue
Block a user