mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -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)
|
l = tweets.is_long(tweet)
|
||||||
while l != False:
|
while l != False:
|
||||||
tweetsList.append(tweet)
|
tweetsList.append(tweet)
|
||||||
id = tweets.get_id(l)
|
|
||||||
try:
|
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"])
|
urls = utils.find_urls_in_text(tweet["text"])
|
||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
||||||
|
@ -174,12 +174,15 @@ class viewTweet(basicTweet):
|
|||||||
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.
|
# 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"
|
value = "message"
|
||||||
else:
|
else:
|
||||||
value = "text"
|
value = "text"
|
||||||
if tweetList[i].has_key("retweeted_status"):
|
if tweetList[i].has_key("retweeted_status") and tweetList[i]["is_quote_status"] == False:
|
||||||
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value])
|
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:
|
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.
|
# tweets with extended_entities could include image descriptions.
|
||||||
@ -198,7 +201,10 @@ 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[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:
|
else:
|
||||||
text = tweet[value]
|
text = tweet[value]
|
||||||
text = self.clear_text(text)
|
text = self.clear_text(text)
|
||||||
|
@ -18,15 +18,10 @@
|
|||||||
############################################################
|
############################################################
|
||||||
from twitter import utils
|
from twitter import utils
|
||||||
|
|
||||||
def get_id(url):
|
|
||||||
return url.split("/")[-1]
|
|
||||||
|
|
||||||
def is_long(tweet):
|
def is_long(tweet):
|
||||||
long = False
|
if tweet.has_key("is_quote_status") and tweet["is_quote_status"] == True:
|
||||||
for url in range(0, len(tweet["entities"]["urls"])):
|
return tweet["quoted_status_id"]
|
||||||
if "twitter.com" in tweet["entities"]["urls"][url]["expanded_url"]:
|
return False
|
||||||
long = get_id(tweet["entities"]["urls"][url]["expanded_url"])
|
|
||||||
return long
|
|
||||||
|
|
||||||
def clear_url(tweet):
|
def clear_url(tweet):
|
||||||
urls = utils.find_urls_in_text(tweet["text"])
|
urls = utils.find_urls_in_text(tweet["text"])
|
||||||
|
@ -426,7 +426,6 @@ class Session(object):
|
|||||||
def check_quoted_status(self, tweet):
|
def check_quoted_status(self, tweet):
|
||||||
status = tweets.is_long(tweet)
|
status = tweets.is_long(tweet)
|
||||||
if status != False:
|
if status != False:
|
||||||
tweet["quoted"] = 1
|
|
||||||
tweet = self.get_quoted_tweet(tweet)
|
tweet = self.get_quoted_tweet(tweet)
|
||||||
return tweet
|
return tweet
|
||||||
|
|
||||||
@ -437,8 +436,7 @@ class Session(object):
|
|||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
try: quoted_tweet["text"] = quoted_tweet["text"].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
|
try: quoted_tweet["text"] = quoted_tweet["text"].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
l = tweets.is_long(quoted_tweet)
|
id = tweets.is_long(quoted_tweet)
|
||||||
id = tweets.get_id(l)
|
|
||||||
try: original_tweet = self.twitter.twitter.show_status(id=id)
|
try: original_tweet = self.twitter.twitter.show_status(id=id)
|
||||||
except: return quoted_tweet
|
except: return quoted_tweet
|
||||||
urls = utils.find_urls_in_text(original_tweet["text"])
|
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"):
|
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[value]))
|
if tweet.has_key("retweeted_status"):
|
||||||
except KeyError: pass
|
if tweet.has_key("message") == False:
|
||||||
#text = "%s" % (StripChars(tweet["text"]))
|
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+"."
|
if text[-1] in chars: text=text+"."
|
||||||
urls = utils.find_urls_in_text(text)
|
urls = utils.find_urls_in_text(text)
|
||||||
for url in range(0, len(urls)):
|
for url in range(0, len(urls)):
|
||||||
|
Loading…
Reference in New Issue
Block a user