diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index 4dc4f23e..c3b8e34b 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -49,6 +49,7 @@ class bufferController(object): def get_event(self, ev): + """ Catches key presses in the WX interface and generate the corresponding event names.""" if ev.GetKeyCode() == wx.WXK_RETURN and ev.ControlDown(): event = "audio" elif ev.GetKeyCode() == wx.WXK_RETURN: event = "url" elif ev.GetKeyCode() == wx.WXK_F5: event = "volume_down" @@ -143,14 +144,14 @@ class bufferController(object): if tweet.image == None: call_threaded(self.session.api_call, call_name="update_status", status=text) else: - call_threaded(self.post_with_media, text=text, image=tweet.image) + call_threaded(self.post_with_media, text=text, image=tweet.image, description="test") if hasattr(tweet.message, "destroy"): tweet.message.destroy() def post_with_media(self, text="", image=None, description=None): if image != None: img = self.session.twitter.twitter.upload_media(media=image) -# if description != None: -# self.session.twitter.twitter.set_description(media_id=img["media_id"], alt_text=description) + if description != None: + self.session.twitter.twitter.set_description(media_id=img["media_id"], alt_text=dict(text=description)) self.session.api_call(call_name="update_status", status=text, media_ids=img["media_id"]) def save_positions(self): @@ -249,9 +250,9 @@ class baseBufferController(bufferController): tweet = self.get_right_tweet() tweetsList = [] tweet_id = tweet["id"] - uri = None - if tweet.has_key("long_uri"): - uri = tweet["long_uri"] + message = None + 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"]) @@ -261,8 +262,8 @@ class baseBufferController(bufferController): except TwythonError as e: utils.twitter_error(e) return - if uri != None: - tweet["text"] = twishort.get_full_text(uri) + if message != None: + tweet["message"] = message l = tweets.is_long(tweet) while l != False: tweetsList.append(tweet) diff --git a/src/controller/messages.py b/src/controller/messages.py index ff64aaa8..bb302e0e 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -165,24 +165,32 @@ class dm(basicTweet): class viewTweet(basicTweet): def __init__(self, tweet, tweetList, is_tweet=True): + """ This represents a tweet displayer. However it could be used for showing something wich is not a tweet, like a direct message or an event. + param tweet: A dictionary that represents a full tweet or a string for non-tweets. + param tweetList: If is_tweet is set to True, this could be a list of quoted tweets. + param is_tweet: True or false, depending wether the passed object is a tweet or not.""" if is_tweet == True: image_description = [] text = "" for i in xrange(0, len(tweetList)): + # tweets with message keys are longer tweets, the message value is the full messaje taken from twishort. if tweetList[i].has_key("message"): value = "message" else: value = "text" if tweetList[i].has_key("retweeted_status"): - text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"][value]) + text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value]) else: text = text + "@%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value]) + # tweets with extended_entities could include image descriptions. if tweetList[i].has_key("extended_entities") and tweetList[i]["extended_entities"].has_key("media"): for z in tweetList[i]["extended_entities"]["media"]: if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: image_description.append(z["ext_alt_text"]) + # set rt and likes counters. rt_count = str(tweet["retweet_count"]) favs_count = str(tweet["favorite_count"]) + # Gets the client from where this tweet was made. source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8"))) if text == "": if tweet.has_key("message"): @@ -190,7 +198,7 @@ class viewTweet(basicTweet): else: value = "text" if tweet.has_key("retweeted_status"): - 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[value]) else: text = tweet[value] text = self.clear_text(text) diff --git a/src/long_tweets/twishort.py b/src/long_tweets/twishort.py index 635545a4..963ac271 100644 --- a/src/long_tweets/twishort.py +++ b/src/long_tweets/twishort.py @@ -51,5 +51,4 @@ def create_tweet(user_token, user_secret, text, media=0): "text": text.encode("utf-8"), "media": media} response = requests.post(url, data=data) -# print response.json() return response.json()["text_to_tweet"] \ No newline at end of file diff --git a/src/twitter/compose.py b/src/twitter/compose.py index f8185ec1..515623aa 100644 --- a/src/twitter/compose.py +++ b/src/twitter/compose.py @@ -50,7 +50,7 @@ def compose_tweet(tweet, db, relative_times): elif tweet.has_key("user"): user = tweet["user"]["name"] source = re.sub(r"(?s)<.*?>", "", tweet["source"]) - try: text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"]["text"])) + try: text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet[value])) except KeyError: pass #text = "%s" % (StripChars(tweet["text"])) if text[-1] in chars: text=text+"." diff --git a/src/twython/endpoints.py b/src/twython/endpoints.py index 47bef239..7691bfd5 100644 --- a/src/twython/endpoints.py +++ b/src/twython/endpoints.py @@ -146,7 +146,7 @@ class EndpointsMixin(object): return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params) def set_description(self, **params): - """ Adds a description to an image.""" + """ Adds a description to an image.""" # This method only accepts strings, no dictionaries. params = json.dumps(params) return self.post("media/metadata/create", params=params)