mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Fixed some things related to twishort's tweets
This commit is contained in:
parent
48232a6cf8
commit
b1cf1c5590
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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"]
|
@ -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+"."
|
||||
|
Loading…
Reference in New Issue
Block a user