some improvements in long tweets

This commit is contained in:
Manuel Cortez 2016-04-28 13:54:06 -05:00
parent a312b7f63c
commit 2268619101
7 changed files with 46 additions and 33 deletions

View File

@ -307,7 +307,9 @@ class baseBufferController(bufferController):
except TwythonError as e:
output.speak(e.message, True)
for i in items:
if utils.is_allowed(i, self.session.settings["twitter"]["ignored_clients"]) == True:
if utils.is_allowed(i, self.session.settings["twitter"]["ignored_clients"]) == True and utils.find_item(i["id"], self.session.db[self.name]) == None:
i = self.session.check_quoted_status(i)
i = self.session.check_long_tweet(i)
elements.append(i)
if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db[self.name].insert(0, i)

View File

@ -169,10 +169,14 @@ class viewTweet(basicTweet):
image_description = []
text = ""
for i in xrange(0, len(tweetList)):
if tweetList[i].has_key("retweeted_status"):
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["text"])
if tweetList[i].has_key("message"):
value = "message"
else:
text = text + "@%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i]["text"])
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])
else:
text = text + "@%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value])
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:
@ -181,10 +185,14 @@ class viewTweet(basicTweet):
favs_count = str(tweet["favorite_count"])
source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8")))
if text == "":
if tweet.has_key("message"):
value = "message"
else:
value = "text"
if tweet.has_key("retweeted_status"):
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet["retweeted_status"]["text"])
else:
text = tweet["text"]
text = tweet[value]
text = self.clear_text(text)
if tweet.has_key("extended_entities") and tweet["extended_entities"].has_key("media"):
for z in tweet["extended_entities"]["media"]:

View File

@ -18,7 +18,7 @@ import os
from mysc.thread_utils import stream_threaded
from pubsub import pub
log = logging.getLogger("sessionmanager.session")
from long_tweets import tweets
from long_tweets import tweets, twishort
sessions = {}
@ -64,6 +64,7 @@ class Session(object):
if utils.find_item(i["id"], self.db[name]) == None and utils.is_allowed(i, self.settings["twitter"]["ignored_clients"]) == True:
try: i = self.check_quoted_status(i)
except: pass
i = self.check_long_tweet(i)
if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i)
else: self.db[name].insert(0, i)
num = num+1
@ -429,9 +430,9 @@ class Session(object):
tweet = self.get_quoted_tweet(tweet)
return tweet
def get_quoted_tweet(self, tweet):
quoted_tweet = self.twitter.twitter.show_status(id=tweet["id"])
quoted_tweet = tweet
urls = utils.find_urls_in_text(quoted_tweet["text"])
for url in range(0, len(urls)):
try: quoted_tweet["text"] = quoted_tweet["text"].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
@ -446,3 +447,8 @@ class Session(object):
except IndexError: pass
return compose.compose_quoted_tweet(quoted_tweet, original_tweet)
def check_long_tweet(self, tweet):
long = twishort.is_long(tweet)
if long != False:
tweet["message"] = twishort.get_full_text(long)
return tweet

View File

@ -36,6 +36,7 @@ class timelinesStreamer(TwythonStreamer):
return
try:
data_ = self.session.check_quoted_status(data)
data_ = self.session.check_long_tweet(data_)
data = data_
except AttributeError:
pass

View File

@ -37,11 +37,12 @@ class streamer(TwythonStreamer):
if utils.find_item(data["id"], self.session.db[place]) != None:
log.error("duplicated tweet. Ignoring it...")
return False
try:
data_ = self.session.check_quoted_status(data)
data = data_
except:
pass
# try:
data_ = self.session.check_quoted_status(data)
data_ = self.session.check_long_tweet(data_)
data = data_
# except:
# pass
if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db[place].append(data)
else:

View File

@ -30,9 +30,6 @@ chars = "abcdefghijklmnopqrstuvwxyz"
def compose_tweet(tweet, db, relative_times):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
long = twishort.is_long(tweet)
if long != False:
tweet["long_uri"] = long
if system == "Windows":
original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en")
if relative_times == True:
@ -41,7 +38,11 @@ def compose_tweet(tweet, db, relative_times):
ts = original_date.replace(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage())
else:
ts = tweet["created_at"]
text = StripChars(tweet["text"])
if tweet.has_key("message"):
value = "message"
else:
value = "text"
text = StripChars(tweet[value])
if tweet.has_key("sender"):
source = "DM"
if db["user_name"] == tweet["sender"]["screen_name"]: user = _(u"Dm to %s ") % (tweet["recipient"]["name"],)
@ -50,26 +51,16 @@ def compose_tweet(tweet, db, relative_times):
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"]))
except KeyError: text = "%s" % (StripChars(tweet["text"]))
except KeyError: pass
#text = "%s" % (StripChars(tweet["text"]))
if text[-1] in chars: text=text+"."
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
if config.app['app-settings']['handle_longtweets'] and 'long_uri' in tweet:
try:
oldtext=text
text=twishort.get_full_text(tweet['long_uri'])
try: text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(text))
except KeyError: pass
except:
text=oldtext
if tweet.has_key("message"):
text = tweet["message"]
return [user+", ", text, ts+", ", source]
tweet["text"] = text
return [user+", ", tweet["text"], ts+", ", source]
if config.app['app-settings']['handle_longtweets']: pass
# return [user+", ", text, ts+", ", source]
return [user+", ", text, ts+", ", source]
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."""

View File

@ -23,7 +23,11 @@ def find_urls_in_text(text):
def find_urls (tweet):
urls = []
return [s[0] for s in url_re.findall(tweet["text"])]
if tweet.has_key("message"):
i = "message"
else:
i = "text"
return [s[0] for s in url_re.findall(tweet[i])]
def find_item(id, listItem):
for i in range(0, len(listItem)):