mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-01-18 16:40:41 -06:00
Fixed some bugs related to extended tweets
This commit is contained in:
parent
2fdbcbc152
commit
378d277a98
@ -24,7 +24,11 @@ def is_long(tweet):
|
||||
return False
|
||||
|
||||
def clear_url(tweet):
|
||||
urls = utils.find_urls_in_text(tweet["full_text"])
|
||||
if tweet.has_key("full_text"):
|
||||
value = "full_text"
|
||||
else:
|
||||
value = "text"
|
||||
urls = utils.find_urls_in_text(tweet[value])
|
||||
try: tweet["message"] = tweet["message"].replace(urls[-1], "")
|
||||
except IndexError: pass
|
||||
return tweet
|
@ -30,8 +30,11 @@ def get_twishort_uri(url):
|
||||
def is_long(tweet):
|
||||
long = False
|
||||
for url in range(0, len(tweet["entities"]["urls"])):
|
||||
if "twishort.com" in tweet["entities"]["urls"][url]["expanded_url"]:
|
||||
long = get_twishort_uri(tweet["entities"]["urls"][url]["expanded_url"])
|
||||
try:
|
||||
if "twishort.com" in tweet["entities"]["urls"][url]["expanded_url"]:
|
||||
long = get_twishort_uri(tweet["entities"]["urls"][url]["expanded_url"])
|
||||
except TypeError:
|
||||
pass
|
||||
return long
|
||||
|
||||
def get_full_text(uri):
|
||||
|
@ -26,8 +26,9 @@ def stream_threaded(func, *args, **kwargs):
|
||||
def new_func(*a, **k):
|
||||
try:
|
||||
func(**k)
|
||||
except:
|
||||
except exception as msg:
|
||||
log.error("Error in stream with args: %r" % (a,))
|
||||
log.error(msg.message)
|
||||
pub.sendMessage("stream-error", session=a[0])
|
||||
|
||||
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
|
||||
|
@ -432,9 +432,13 @@ class Session(object):
|
||||
|
||||
def get_quoted_tweet(self, tweet):
|
||||
quoted_tweet = tweet
|
||||
urls = utils.find_urls_in_text(quoted_tweet["full_text"])
|
||||
if tweet.has_key("full_text"):
|
||||
value = "full_text"
|
||||
else:
|
||||
value = "text"
|
||||
urls = utils.find_urls_in_text(quoted_tweet[value])
|
||||
for url in range(0, len(urls)):
|
||||
try: quoted_tweet["full_text"] = quoted_tweet["full_text"].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
|
||||
try: quoted_tweet[value] = quoted_tweet[value].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
|
||||
except IndexError: pass
|
||||
id = tweets.is_long(quoted_tweet)
|
||||
try: original_tweet = self.twitter.twitter.show_status(id=id, tweet_mode="extended")
|
||||
|
@ -71,7 +71,7 @@ class timelinesStreamer(TwythonStreamer):
|
||||
if "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
||||
if data.has_key("extended_tweet"):
|
||||
data["full_text"] = data["extended_tweet"]["full_text"]
|
||||
data["entities"] = data["extended_tweet"]["entities"]
|
||||
# data["entities"] = data["extended_tweet"]["entities"]
|
||||
# log.error(data["extended_entities"])
|
||||
self.check_tls(data)
|
||||
# except:
|
||||
|
@ -137,8 +137,9 @@ class streamer(TwythonStreamer):
|
||||
elif "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
||||
if data.has_key("extended_tweet"):
|
||||
data["full_text"] = data["extended_tweet"]["full_text"]
|
||||
data["entities"] = data["extended_tweet"]["entities"]
|
||||
# log.error("Extended tweet")
|
||||
# data["entities"].extend(data["extended_tweet"]["entities"])
|
||||
# log.error(data["extended_tweet"])
|
||||
# log.error("Extended tweet")
|
||||
if data["user"]["id"] in self.muted_users: return
|
||||
self.check_mentions(data)
|
||||
self.check_send(data)
|
||||
|
@ -59,8 +59,11 @@ def compose_tweet(tweet, db, relative_times):
|
||||
if tweet.has_key("message") == False:
|
||||
urls = utils.find_urls_in_text(text)
|
||||
for url in range(0, len(urls)):
|
||||
try: text = text.replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
||||
except IndexError: pass
|
||||
try:
|
||||
log.error(urls[url])
|
||||
log.error(tweet["entities"]["urls"][url])
|
||||
text = text.replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
|
||||
except: pass
|
||||
if config.app['app-settings']['handle_longtweets']: pass
|
||||
# return [user+", ", text, ts+", ", source]
|
||||
return [user+", ", text, ts+", ", source]
|
||||
@ -88,18 +91,24 @@ def compose_dm(tweet, db, relative_times):
|
||||
|
||||
def compose_quoted_tweet(quoted_tweet, original_tweet):
|
||||
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
|
||||
text = StripChars(quoted_tweet["full_text"])
|
||||
if quoted_tweet.has_key("full_text"):
|
||||
value = "full_text"
|
||||
else:
|
||||
value = "text"
|
||||
text = StripChars(quoted_tweet[value])
|
||||
quoting_user = quoted_tweet["user"]["name"]
|
||||
source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"])
|
||||
try: text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], StripChars(quoted_tweet["retweeted_status"]["full_text"]))
|
||||
except KeyError: text = "%s" % (StripChars(quoted_tweet["full_text"]))
|
||||
try: text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], StripChars(quoted_tweet["retweeted_status"][value]))
|
||||
except KeyError: text = "%s" % (StripChars(quoted_tweet[value]))
|
||||
if text[-1] in chars: text=text+"."
|
||||
original_user = original_tweet["user"]["screen_name"]
|
||||
if original_tweet.has_key("message"):
|
||||
original_text = StripChars(original_tweet["message"])
|
||||
else:
|
||||
elif original_tweet.has_key("full_text"):
|
||||
original_text = StripChars(original_tweet["full_text"])
|
||||
quoted_tweet["message"] = _(u"{0}. Quoted tweet from @{1}: {2}").format( quoted_tweet["full_text"], original_user, original_text)
|
||||
else:
|
||||
original_text = StripChars(original_tweet["text"])
|
||||
quoted_tweet["message"] = _(u"{0}. Quoted tweet from @{1}: {2}").format( quoted_tweet[value], original_user, original_text)
|
||||
quoted_tweet = tweets.clear_url(quoted_tweet)
|
||||
return quoted_tweet
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user