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):
|
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"
|
if ev.GetKeyCode() == wx.WXK_RETURN and ev.ControlDown(): event = "audio"
|
||||||
elif ev.GetKeyCode() == wx.WXK_RETURN: event = "url"
|
elif ev.GetKeyCode() == wx.WXK_RETURN: event = "url"
|
||||||
elif ev.GetKeyCode() == wx.WXK_F5: event = "volume_down"
|
elif ev.GetKeyCode() == wx.WXK_F5: event = "volume_down"
|
||||||
@ -143,14 +144,14 @@ class bufferController(object):
|
|||||||
if tweet.image == None:
|
if tweet.image == None:
|
||||||
call_threaded(self.session.api_call, call_name="update_status", status=text)
|
call_threaded(self.session.api_call, call_name="update_status", status=text)
|
||||||
else:
|
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()
|
if hasattr(tweet.message, "destroy"): tweet.message.destroy()
|
||||||
|
|
||||||
def post_with_media(self, text="", image=None, description=None):
|
def post_with_media(self, text="", image=None, description=None):
|
||||||
if image != None:
|
if image != None:
|
||||||
img = self.session.twitter.twitter.upload_media(media=image)
|
img = self.session.twitter.twitter.upload_media(media=image)
|
||||||
# if description != None:
|
if description != None:
|
||||||
# self.session.twitter.twitter.set_description(media_id=img["media_id"], alt_text=description)
|
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"])
|
self.session.api_call(call_name="update_status", status=text, media_ids=img["media_id"])
|
||||||
|
|
||||||
def save_positions(self):
|
def save_positions(self):
|
||||||
@ -249,9 +250,9 @@ class baseBufferController(bufferController):
|
|||||||
tweet = self.get_right_tweet()
|
tweet = self.get_right_tweet()
|
||||||
tweetsList = []
|
tweetsList = []
|
||||||
tweet_id = tweet["id"]
|
tweet_id = tweet["id"]
|
||||||
uri = None
|
message = None
|
||||||
if tweet.has_key("long_uri"):
|
if tweet.has_key("message"):
|
||||||
uri = tweet["long_uri"]
|
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)
|
||||||
urls = utils.find_urls_in_text(tweet["text"])
|
urls = utils.find_urls_in_text(tweet["text"])
|
||||||
@ -261,8 +262,8 @@ class baseBufferController(bufferController):
|
|||||||
except TwythonError as e:
|
except TwythonError as e:
|
||||||
utils.twitter_error(e)
|
utils.twitter_error(e)
|
||||||
return
|
return
|
||||||
if uri != None:
|
if message != None:
|
||||||
tweet["text"] = twishort.get_full_text(uri)
|
tweet["message"] = message
|
||||||
l = tweets.is_long(tweet)
|
l = tweets.is_long(tweet)
|
||||||
while l != False:
|
while l != False:
|
||||||
tweetsList.append(tweet)
|
tweetsList.append(tweet)
|
||||||
|
@ -165,24 +165,32 @@ class dm(basicTweet):
|
|||||||
|
|
||||||
class viewTweet(basicTweet):
|
class viewTweet(basicTweet):
|
||||||
def __init__(self, tweet, tweetList, is_tweet=True):
|
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:
|
if is_tweet == True:
|
||||||
image_description = []
|
image_description = []
|
||||||
text = ""
|
text = ""
|
||||||
for i in xrange(0, len(tweetList)):
|
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"):
|
if tweetList[i].has_key("message"):
|
||||||
value = "message"
|
value = "message"
|
||||||
else:
|
else:
|
||||||
value = "text"
|
value = "text"
|
||||||
if tweetList[i].has_key("retweeted_status"):
|
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:
|
else:
|
||||||
text = text + "@%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value])
|
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"):
|
if tweetList[i].has_key("extended_entities") and tweetList[i]["extended_entities"].has_key("media"):
|
||||||
for z in tweetList[i]["extended_entities"]["media"]:
|
for z in tweetList[i]["extended_entities"]["media"]:
|
||||||
if z.has_key("ext_alt_text") and z["ext_alt_text"] != None:
|
if z.has_key("ext_alt_text") and z["ext_alt_text"] != None:
|
||||||
image_description.append(z["ext_alt_text"])
|
image_description.append(z["ext_alt_text"])
|
||||||
|
# set rt and likes counters.
|
||||||
rt_count = str(tweet["retweet_count"])
|
rt_count = str(tweet["retweet_count"])
|
||||||
favs_count = str(tweet["favorite_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")))
|
source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8")))
|
||||||
if text == "":
|
if text == "":
|
||||||
if tweet.has_key("message"):
|
if tweet.has_key("message"):
|
||||||
@ -190,7 +198,7 @@ class viewTweet(basicTweet):
|
|||||||
else:
|
else:
|
||||||
value = "text"
|
value = "text"
|
||||||
if tweet.has_key("retweeted_status"):
|
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:
|
else:
|
||||||
text = tweet[value]
|
text = tweet[value]
|
||||||
text = self.clear_text(text)
|
text = self.clear_text(text)
|
||||||
|
@ -51,5 +51,4 @@ def create_tweet(user_token, user_secret, text, media=0):
|
|||||||
"text": text.encode("utf-8"),
|
"text": text.encode("utf-8"),
|
||||||
"media": media}
|
"media": media}
|
||||||
response = requests.post(url, data=data)
|
response = requests.post(url, data=data)
|
||||||
# print response.json()
|
|
||||||
return response.json()["text_to_tweet"]
|
return response.json()["text_to_tweet"]
|
@ -50,7 +50,7 @@ def compose_tweet(tweet, db, relative_times):
|
|||||||
elif tweet.has_key("user"):
|
elif tweet.has_key("user"):
|
||||||
user = tweet["user"]["name"]
|
user = tweet["user"]["name"]
|
||||||
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
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
|
except KeyError: pass
|
||||||
#text = "%s" % (StripChars(tweet["text"]))
|
#text = "%s" % (StripChars(tweet["text"]))
|
||||||
if text[-1] in chars: text=text+"."
|
if text[-1] in chars: text=text+"."
|
||||||
|
@ -146,7 +146,7 @@ class EndpointsMixin(object):
|
|||||||
return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params)
|
return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params)
|
||||||
|
|
||||||
def set_description(self, **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.
|
# This method only accepts strings, no dictionaries.
|
||||||
params = json.dumps(params)
|
params = json.dumps(params)
|
||||||
return self.post("media/metadata/create", params=params)
|
return self.post("media/metadata/create", params=params)
|
||||||
|
Loading…
Reference in New Issue
Block a user