From df345b5eecf7e777a187f1362d5f9812fdd58975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Wed, 28 Sep 2016 17:25:03 -0500 Subject: [PATCH] Initial support for extended tweets --- src/controller/buffersController.py | 43 ++++++++------------- src/controller/mainController.py | 20 +++++----- src/controller/messages.py | 15 ++++---- src/long_tweets/tweets.py | 2 +- src/sessionmanager/session.py | 10 ++--- src/twitter/buffers/indibidual.py | 13 ++++--- src/twitter/buffers/stream.py | 4 ++ src/twitter/compose.py | 60 +++++++++++++++++++---------- src/twitter/utils.py | 5 ++- src/wxUI/dialogs/message.py | 2 +- 10 files changed, 98 insertions(+), 76 deletions(-) diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index 118dc460..d364c28c 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -224,7 +224,7 @@ class emptyPanel(bufferController): self.needs_init = True 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) log.debug("Initializing buffer %s, account %s" % (name, account,)) if bufferType != None: @@ -235,7 +235,7 @@ class baseBufferController(bufferController): self.name = name self.type = self.buffer.type self.session = sessionObject - self.compose_function = compose.compose_tweet + self.compose_function = getattr(compose, compose_func) log.debug("Compose_function: %s" % (self.compose_function,)) self.account = account self.buffer.account = account @@ -258,10 +258,10 @@ class baseBufferController(bufferController): if tweet.has_key("message"): message = tweet["message"] try: - tweet = self.session.twitter.twitter.show_status(id=tweet_id, include_ext_alt_text=True) - urls = utils.find_urls_in_text(tweet["text"]) + 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["full_text"]) 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 TwythonError as e: utils.twitter_error(e) @@ -272,10 +272,10 @@ class baseBufferController(bufferController): while l != False: tweetsList.append(tweet) try: - tweet = self.session.twitter.twitter.show_status(id=l, include_ext_alt_text=True) - urls = utils.find_urls_in_text(tweet["text"]) + tweet = self.session.twitter.twitter.show_status(id=l, include_ext_alt_text=True, tweet_mode="extended") + urls = utils.find_urls_in_text(tweet["full_text"]) 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 TwythonError as e: utils.twitter_error(e) @@ -479,8 +479,8 @@ class baseBufferController(bufferController): tweet = self.get_right_tweet() screen_name = tweet["user"]["screen_name"] id = tweet["id"] - users = 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) + users = len(utils.get_all_mentioned(tweet, self.session.db)) + 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: self.session.settings["mysc"]["twishort_enabled"] = message.message.long_tweet.GetValue() text = message.message.get_text() @@ -490,9 +490,9 @@ class baseBufferController(bufferController): else: text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1) 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: - 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() @_tweets_exist @@ -534,14 +534,14 @@ class baseBufferController(bufferController): self._retweet_with_comment(tweet, id) 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 != '': retweet.message.set_text(comment) if retweet.message.get_response() == widgetUtils.OK: text = retweet.message.get_text() comments=text - if len(text+ u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["text"])) < 140: - text = text+u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["text"]) + if len(text+ u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["full_text"])) < 140: + text = text+u"“@%s: %s ”" % (tweet["user"]["screen_name"], tweet["full_text"]) else: answer = commonMessageDialogs.retweet_as_link(self.buffer) if answer == widgetUtils.YES: @@ -1100,7 +1100,7 @@ class conversationBufferController(searchBufferController): tweet = self.tweet while tweet["in_reply_to_status_id"] != None: 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: break self.statuses.insert(0, tweet) @@ -1108,7 +1108,7 @@ class conversationBufferController(searchBufferController): if tweet["in_reply_to_status_id"] == None: self.kwargs["since_id"] = 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: if i["in_reply_to_status_id"] in self.ids: self.statuses.append(i) @@ -1128,12 +1128,3 @@ class conversationBufferController(searchBufferController): return True elif dlg == widgetUtils.NO: 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)) diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 7bce481e..156b789d 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -293,27 +293,27 @@ class Controller(object): self.view.add_buffer(account.buffer , name=session.db["user_name"]) for i in session.settings['general']['buffer_order']: 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.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) 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.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) 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.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': - 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.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': - 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.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': - 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.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.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"]: - 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.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"]) 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"])) 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.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) @@ -375,7 +375,7 @@ class Controller(object): 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"])) 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) 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"])) @@ -383,7 +383,7 @@ class Controller(object): 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"])) 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.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) diff --git a/src/controller/messages.py b/src/controller/messages.py index 6201aeef..a2acdcfd 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -147,10 +147,11 @@ class tweet(basicTweet): class reply(tweet): def __init__(self, session, title, caption, text, twishort_enabled, users=None): super(reply, self).__init__(session, title, caption, text, twishort_enabled, messageType="reply") - self.users = users - if self.users != None and len(self.users) > 1: - widgetUtils.connect_event(self.message.mentionAll, widgetUtils.BUTTON_PRESSED, self.mention_all) + self.message.mentionAll.SetValue(True) + if users > 1: +# widgetUtils.connect_event(self.message.mentionAll, widgetUtils.CHECKBOX, self.mention_all) self.message.enable_button("mentionAll") + self.message.mentionAll.SetValue(False) self.message.set_cursor_at_end() self.text_processor() @@ -184,10 +185,10 @@ class viewTweet(basicTweet): if tweetList[i].has_key("message") and tweetList[i]["is_quote_status"] == False: value = "message" 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("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: text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value]) else: @@ -206,10 +207,10 @@ class viewTweet(basicTweet): if tweet.has_key("message"): value = "message" else: - value = "text" + value = "full_text" if tweet.has_key("retweeted_status"): 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: text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value]) else: diff --git a/src/long_tweets/tweets.py b/src/long_tweets/tweets.py index 9ad3d7a3..dafb5956 100644 --- a/src/long_tweets/tweets.py +++ b/src/long_tweets/tweets.py @@ -24,7 +24,7 @@ def is_long(tweet): return False 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], "") except IndexError: pass return tweet \ No newline at end of file diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index 24e754ff..14b0904d 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -432,17 +432,17 @@ class Session(object): def get_quoted_tweet(self, 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)): - 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 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 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)): - 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 return compose.compose_quoted_tweet(quoted_tweet, original_tweet) diff --git a/src/twitter/buffers/indibidual.py b/src/twitter/buffers/indibidual.py index 98fb23f5..dcc66247 100644 --- a/src/twitter/buffers/indibidual.py +++ b/src/twitter/buffers/indibidual.py @@ -67,8 +67,11 @@ class timelinesStreamer(TwythonStreamer): self.friends = friends def on_success(self, data): - try: - if "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True: - self.check_tls(data) - except: - pass +# try: + if "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"] + self.check_tls(data) +# except: +# pass diff --git a/src/twitter/buffers/stream.py b/src/twitter/buffers/stream.py index 46b7b504..503c29ad 100644 --- a/src/twitter/buffers/stream.py +++ b/src/twitter/buffers/stream.py @@ -135,6 +135,10 @@ class streamer(TwythonStreamer): self.friends = data["friends"] pub.sendMessage("friends-receibed") 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 self.check_mentions(data) self.check_send(data) diff --git a/src/twitter/compose.py b/src/twitter/compose.py index 9d33b78e..21950446 100644 --- a/src/twitter/compose.py +++ b/src/twitter/compose.py @@ -40,24 +40,23 @@ def compose_tweet(tweet, db, relative_times): ts = tweet["created_at"] if tweet.has_key("message"): value = "message" + log.error(tweet["message"]) + elif tweet.has_key("full_text"): + value = "full_text" else: value = "text" + log.exception(tweet.keys()) text = StripChars(tweet[value]) - if tweet.has_key("sender"): - source = "DM" - if db["user_name"] == tweet["sender"]["screen_name"]: user = _(u"Dm to %s ") % (tweet["recipient"]["name"],) - else: user = tweet["sender"]["name"] - elif tweet.has_key("user"): - user = tweet["user"]["name"] - source = re.sub(r"(?s)<.*?>", "", tweet["source"]) - if tweet.has_key("retweeted_status"): - 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["retweeted_status"]["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+"." + user = tweet["user"]["name"] + source = re.sub(r"(?s)<.*?>", "", tweet["source"]) + if tweet.has_key("retweeted_status"): + 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["retweeted_status"][value])) + 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: urls = utils.find_urls_in_text(text) 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] +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): """ 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"] 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"])) - except KeyError: text = "%s" % (StripChars(quoted_tweet["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["full_text"])) if text[-1] in chars: text=text+"." original_user = original_tweet["user"]["screen_name"] if original_tweet.has_key("message"): original_text = StripChars(original_tweet["message"]) else: - original_text = StripChars(original_tweet["text"]) - quoted_tweet["message"] = _(u"{0}. Quoted tweet from @{1}: {2}").format( quoted_tweet["text"], original_user, original_text) + original_text = StripChars(original_tweet["full_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) return quoted_tweet diff --git a/src/twitter/utils.py b/src/twitter/utils.py index 6978d22c..60fc1586 100644 --- a/src/twitter/utils.py +++ b/src/twitter/utils.py @@ -25,6 +25,8 @@ def find_urls (tweet): urls = [] if tweet.has_key("message"): i = "message" + elif tweet.has_key("full_text"): + i = "full_text" else: i = "text" return [s[0] for s in url_re.findall(tweet[i])] @@ -57,6 +59,7 @@ def is_audio(tweet): if i["text"] == "audio": return True except: + print tweet["entities"]["hashtags"] log.exception("Exception while executing is_audio hashtag algorithm") def is_geocoded(tweet): @@ -120,7 +123,7 @@ def is_allowed(tweet, clients): for i in clients: if i.lower() == source.lower(): allowed = False - log.exception("Tuit not allowed: %s" % (tweet["text"],)) +# log.exception("Tuit not allowed: %r" % (tweet,)) return allowed def twitter_error(error): diff --git a/src/wxUI/dialogs/message.py b/src/wxUI/dialogs/message.py index 60919ffc..db29f81f 100644 --- a/src/wxUI/dialogs/message.py +++ b/src/wxUI/dialogs/message.py @@ -234,7 +234,7 @@ class reply(tweet): def __init__(self, title, message, text): super(reply, self).__init__(message, title, text) 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.buttonsBox1.Add(self.mentionAll, 0, wx.ALL, 5) self.buttonsBox1.Layout()