From 74bcc3696840816a75c6d4ff17bdea9841cc0407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Mon, 13 Jul 2015 04:45:06 -0500 Subject: [PATCH] Added full Twishort support --- src/controller/buffersController.py | 15 +++++++++++++-- src/long_tweets/twishort.py | 10 +++++++++- src/wxUI/dialogs/message.py | 2 ++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index b2a1b1d6..12f94492 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -130,6 +130,11 @@ class bufferController(object): tweet = messages.tweet(self.session, title, caption, "") if tweet.message.get_response() == widgetUtils.OK: text = tweet.message.get_text() + if len(text) > 140 and tweet.message.get("long_tweet") == True: + if tweet.image == None: + text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text) + else: + text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1) if tweet.image == None: call_threaded(self.session.api_call, call_name="update_status", status=text) else: @@ -371,10 +376,16 @@ class baseBufferController(bufferController): 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,), users) if message.message.get_response() == widgetUtils.OK: + text = message.message.get_text() + if len(text) > 140 and message.message.get("long_tweet") == True: + if message.image == None: + text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text) + 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=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=text) else: - 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) + 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) if hasattr(message.message, "destroy"): message.message.destroy() @_tweets_exist diff --git a/src/long_tweets/twishort.py b/src/long_tweets/twishort.py index 69b17d6d..b42eb42f 100644 --- a/src/long_tweets/twishort.py +++ b/src/long_tweets/twishort.py @@ -35,4 +35,12 @@ def get_full_text(uri): r = requests.get("http://api.twishort.com/1.1/get.json", params={"uri": uri, "api_key": keys.keyring.get("twishort_api_key")}) return r.json()["text"] # except: -# return False \ No newline at end of file +# return False + +def create_tweet(user_token, user_secret, text, media=0): + data = {"user_token": user_token, + "user_secret": user_secret, + "text": text.encode("utf-8"), + "media": media} + response = requests.post("http://twblue.es/twishort.php", data=data) + return response.json()["text_to_tweet"] \ No newline at end of file diff --git a/src/wxUI/dialogs/message.py b/src/wxUI/dialogs/message.py index 7f27fadf..2bd19ab2 100644 --- a/src/wxUI/dialogs/message.py +++ b/src/wxUI/dialogs/message.py @@ -73,6 +73,8 @@ class tweet(textLimited): self.mainBox = wx.BoxSizer(wx.VERTICAL) self.createTextArea(message, text) self.mainBox.Add(self.textBox, 0, wx.ALL, 5) + self.long_tweet = wx.CheckBox(self.panel, -1, _(u"Long tweet")) + self.long_tweet.SetValue(True) self.upload_image = wx.Button(self.panel, -1, _(u"Upload image..."), size=wx.DefaultSize) self.spellcheck = wx.Button(self.panel, -1, _("Check spelling..."), size=wx.DefaultSize) self.attach = wx.Button(self.panel, -1, _(u"Attach audio..."), size=wx.DefaultSize)