mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Changed way of detecting quoted statuses. Parsing improvements in tweet displayer
This commit is contained in:
parent
b1cf1c5590
commit
da39f40048
@ -267,9 +267,8 @@ class baseBufferController(bufferController):
|
||||
l = tweets.is_long(tweet)
|
||||
while l != False:
|
||||
tweetsList.append(tweet)
|
||||
id = tweets.get_id(l)
|
||||
try:
|
||||
tweet = self.session.twitter.twitter.show_status(id=id, include_ext_alt_text=True)
|
||||
tweet = self.session.twitter.twitter.show_status(id=l, include_ext_alt_text=True)
|
||||
urls = utils.find_urls_in_text(tweet["text"])
|
||||
for url in range(0, len(urls)):
|
||||
try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
||||
|
@ -174,12 +174,15 @@ class viewTweet(basicTweet):
|
||||
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"):
|
||||
if tweetList[i].has_key("message") and tweetList[i]["is_quote_status"] == False:
|
||||
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][value])
|
||||
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"])
|
||||
else:
|
||||
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.
|
||||
@ -198,7 +201,10 @@ class viewTweet(basicTweet):
|
||||
else:
|
||||
value = "text"
|
||||
if tweet.has_key("retweeted_status"):
|
||||
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value])
|
||||
if tweet.has_key("message") == False:
|
||||
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet["retweeted_status"]["text"])
|
||||
else:
|
||||
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value])
|
||||
else:
|
||||
text = tweet[value]
|
||||
text = self.clear_text(text)
|
||||
|
@ -18,15 +18,10 @@
|
||||
############################################################
|
||||
from twitter import utils
|
||||
|
||||
def get_id(url):
|
||||
return url.split("/")[-1]
|
||||
|
||||
def is_long(tweet):
|
||||
long = False
|
||||
for url in range(0, len(tweet["entities"]["urls"])):
|
||||
if "twitter.com" in tweet["entities"]["urls"][url]["expanded_url"]:
|
||||
long = get_id(tweet["entities"]["urls"][url]["expanded_url"])
|
||||
return long
|
||||
if tweet.has_key("is_quote_status") and tweet["is_quote_status"] == True:
|
||||
return tweet["quoted_status_id"]
|
||||
return False
|
||||
|
||||
def clear_url(tweet):
|
||||
urls = utils.find_urls_in_text(tweet["text"])
|
||||
|
@ -426,7 +426,6 @@ class Session(object):
|
||||
def check_quoted_status(self, tweet):
|
||||
status = tweets.is_long(tweet)
|
||||
if status != False:
|
||||
tweet["quoted"] = 1
|
||||
tweet = self.get_quoted_tweet(tweet)
|
||||
return tweet
|
||||
|
||||
@ -437,8 +436,7 @@ class Session(object):
|
||||
for url in range(0, len(urls)):
|
||||
try: quoted_tweet["text"] = quoted_tweet["text"].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
|
||||
except IndexError: pass
|
||||
l = tweets.is_long(quoted_tweet)
|
||||
id = tweets.get_id(l)
|
||||
id = tweets.is_long(quoted_tweet)
|
||||
try: original_tweet = self.twitter.twitter.show_status(id=id)
|
||||
except: return quoted_tweet
|
||||
urls = utils.find_urls_in_text(original_tweet["text"])
|
||||
|
@ -50,9 +50,11 @@ 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[value]))
|
||||
except KeyError: pass
|
||||
#text = "%s" % (StripChars(tweet["text"]))
|
||||
if tweet.has_key("retweeted_status"):
|
||||
if tweet.has_key("message") == False:
|
||||
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"]["text"]))
|
||||
else:
|
||||
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet[value]))
|
||||
if text[-1] in chars: text=text+"."
|
||||
urls = utils.find_urls_in_text(text)
|
||||
for url in range(0, len(urls)):
|
||||
|
Loading…
Reference in New Issue
Block a user