Added more changes in order to deal with tweet objects

This commit is contained in:
2020-12-22 17:29:33 -06:00
parent 56103466fa
commit 7ceb806af2
4 changed files with 183 additions and 182 deletions

View File

@@ -39,41 +39,41 @@ chars = "abcdefghijklmnopqrstuvwxyz"
def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=None):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
if system == "Windows":
original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en")
original_date = arrow.get(tweet.created_at, "ddd MMM DD H:m:s Z YYYY", locale="en")
if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2])
else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else:
ts = tweet["created_at"]
if "message" in tweet:
ts = tweet.created_at
if hasattr(tweet, "message"):
value = "message"
elif "full_text" in tweet:
elif hasattr(tweet, "full_text"):
value = "full_text"
else:
value = "text"
if "retweeted_status" in tweet and value != "message":
text = StripChars(tweet["retweeted_status"][value])
if hasattr(tweet, "retweeted_status") and value != "message":
text = StripChars(getattr(tweet.retweeted_status, value))
else:
text = StripChars(tweet[value])
text = StripChars(getattr(tweet, value))
if show_screen_names:
user = tweet["user"]["screen_name"]
user = tweet.user.screen_name
else:
user = tweet["user"]["name"]
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
if "retweeted_status" in tweet:
if ("message" in tweet) == False and tweet["retweeted_status"]["is_quote_status"] == False:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text)
elif tweet["retweeted_status"]["is_quote_status"]:
user = tweet.user.name
source = re.sub(r"(?s)<.*?>", "", tweet.source)
if hasattr(tweet, "retweeted_status"):
if (hasattr(tweet, "message")) == False and tweet.retweeted_status.is_quote_status == False:
text = "RT @%s: %s" % (tweet.retweeted_status.user.screen_name, text)
elif tweet.retweeted_status.is_quote_status:
text = "%s" % (text)
else:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text)
if ("message" in tweet) == False:
text = "RT @%s: %s" % (tweet.retweeted_status.user.screen_name, text)
if not hasattr(tweet, "message"):
if "retweeted_status" in tweet:
text = utils.expand_urls(text, tweet["retweeted_status"]["entities"])
if hasattr(tweet, "retweeted_status"):
text = utils.expand_urls(text, tweet.retweeted_status.entities)
else:
text = utils.expand_urls(text, tweet["entities"])
text = utils.expand_urls(text, tweet.entities)
if config.app['app-settings']['handle_longtweets']: pass
return [user+", ", text, ts+", ", source]
@@ -83,76 +83,76 @@ def compose_direct_message(item, db, relative_times, show_screen_names=False, se
if system == "Windows":
# Let's remove the last 3 digits in the timestamp string.
# Twitter sends their "epoch" timestamp with 3 digits for milliseconds and arrow doesn't like it.
original_date = arrow.get(int(item["created_timestamp"][:-3]))
original_date = arrow.get(int(item.created_timestamp[:-3]))
if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2])
else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else:
ts = item["created_timestamp"]
text = StripChars(item["message_create"]["message_data"]["text"])
ts = item.created_timestamp
text = StripChars(item.message_create.message_data.text)
source = "DM"
sender = session.get_user(item["message_create"]["sender_id"])
if db["user_name"] == sender["screen_name"]:
sender = session.get_user(item.message_create.sender_id)
if db["user_name"] == sender.screen_name:
if show_screen_names:
user = _(u"Dm to %s ") % (session.get_user(item["message_create"]["target"]["recipient_id"])["screen_name"])
user = _(u"Dm to %s ") % (session.get_user(item.message_create.target.recipient_id).screen_name)
else:
user = _(u"Dm to %s ") % (session.get_user(item["message_create"]["target"]["recipient_id"])["name"])
user = _(u"Dm to %s ") % (session.get_user(item.message_create.target.recipient_id).name)
else:
if show_screen_names:
user = sender["screen_name"]
user = sender.screen_name
else:
user = sender["name"]
user = sender.name
if text[-1] in chars: text=text+"."
text = utils.expand_urls(text, item["message_create"]["message_data"]["entities"])
text = utils.expand_urls(text, item.message_create.message_data.entities)
return [user+", ", text, ts+", ", source]
def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False, session=None):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
if "retweeted_status" in quoted_tweet:
if "full_text" in quoted_tweet["retweeted_status"]:
if hasattr(quoted_tweet, "retweeted_status"):
if hasattr(quoted_tweet.retweeted_status, "full_text"):
value = "full_text"
else:
value = "text"
text = StripChars(quoted_tweet["retweeted_status"][value])
text = StripChars(getattr(quoted_tweet.retweeted_status, value))
else:
if "full_text" in quoted_tweet:
if hasattr(quoted_tweet, "full_text"):
value = "full_text"
else:
value = "text"
text = StripChars(quoted_tweet[value])
text = StripChars(getattr(quoted_tweet, value))
if show_screen_names:
quoting_user = quoted_tweet["user"]["screen_name"]
quoting_user = quoted_tweet.user.screen_name
else:
quoting_user = quoted_tweet["user"]["name"]
source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"])
if "retweeted_status" in quoted_tweet:
text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], text)
quoting_user = quoted_tweet.user.name
source = re.sub(r"(?s)<.*?>", "", quoted_tweet.source)
if hasattr(quoted_tweet, "retweeted_status"):
text = "rt @%s: %s" % (quoted_tweet.retweeted_status.user.screen_name, text)
if text[-1] in chars: text=text+"."
original_user = original_tweet["user"]["screen_name"]
if "message" in original_tweet:
original_text = original_tweet["message"]
elif "full_text" in original_tweet:
original_text = StripChars(original_tweet["full_text"])
original_user = original_tweet.user.screen_name
if hasattr(original_tweet, "message"):
original_text = original_tweet.message
elif hasattr(original_tweet, "full_text"):
original_text = StripChars(original_tweet.full_text)
else:
original_text = StripChars(original_tweet["text"])
quoted_tweet["message"] = _(u"{0}. Quoted tweet from @{1}: {2}").format( text, original_user, original_text)
original_text = StripChars(original_tweet.text)
quoted_tweet.message = _(u"{0}. Quoted tweet from @{1}: {2}").format( text, original_user, original_text)
quoted_tweet = tweets.clear_url(quoted_tweet)
quoted_tweet["entities"]["urls"].extend(original_tweet["entities"]["urls"])
quoted_tweet.entities.urls.extend(original_tweet.entities.urls)
return quoted_tweet
def compose_followers_list(tweet, db, relative_times=True, show_screen_names=False, session=None):
if system == "Windows":
original_date = arrow.get(tweet["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en")
original_date = arrow.get(tweet.created_at, "ddd MMM D H:m:s Z YYYY", locale="en")
if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2])
else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else:
ts = tweet["created_at"]
if "status" in tweet:
if len(tweet["status"]) > 4 and system == "Windows":
original_date2 = arrow.get(tweet["status"]["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en")
ts = tweet.created_at
if hasattr(tweet, "status"):
if len(tweet.status) > 4 and system == "Windows":
original_date2 = arrow.get(tweet.status.created_at, "ddd MMM D H:m:s Z YYYY", locale="en")
if relative_times:
ts2 = original_date2.humanize(locale=languageHandler.curLang[:2])
else:
@@ -161,14 +161,14 @@ def compose_followers_list(tweet, db, relative_times=True, show_screen_names=Fal
ts2 = _("Unavailable")
else:
ts2 = _("Unavailable")
return [_(u"%s (@%s). %s followers, %s friends, %s tweets. Last tweeted %s. Joined Twitter %s") % (tweet["name"], tweet["screen_name"], tweet["followers_count"], tweet["friends_count"], tweet["statuses_count"], ts2, ts)]
return [_(u"%s (@%s). %s followers, %s friends, %s tweets. Last tweeted %s. Joined Twitter %s") % (tweet.name, tweet.screen_name, tweet.followers_count, tweet.friends_count, tweet.statuses_count, ts2, ts)]
def compose_list(list):
name = list["name"]
if list["description"] == None: description = _(u"No description available")
else: description = list["description"]
user = list["user"]["name"]
members = str(list["member_count"])
if list["mode"] == "private": status = _(u"private")
name = list.name
if list.description == None: description = _(u"No description available")
else: description = list.description
user = list.user.name
members = str(list.member_count)
if list.mode == "private": status = _(u"private")
else: status = _(u"public")
return [name, description, user, members, status]