Added more changes in order to deal with tweet objects

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

View File

@ -304,15 +304,15 @@ class Controller(object):
self.view.add_buffer(account.buffer , name=session.db["user_name"]) self.view.add_buffer(account.buffer , name=session.db["user_name"])
for i in session.settings['general']['buffer_order']: for i in session.settings['general']['buffer_order']:
if i == 'home': if i == 'home':
home = twitterBuffers.baseBufferController(self.view.nb, "get_home_timeline", "home_timeline", session, session.db["user_name"], sound="tweet_received.ogg", tweet_mode="extended") home = twitterBuffers.baseBufferController(self.view.nb, "home_timeline", "home_timeline", session, session.db["user_name"], sound="tweet_received.ogg", tweet_mode="extended")
self.buffers.append(home) self.buffers.append(home)
self.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'mentions': elif i == 'mentions':
mentions = twitterBuffers.baseBufferController(self.view.nb, "get_mentions_timeline", "mentions", session, session.db["user_name"], sound="mention_received.ogg", tweet_mode="extended") mentions = twitterBuffers.baseBufferController(self.view.nb, "mentions_timeline", "mentions", session, session.db["user_name"], sound="mention_received.ogg", tweet_mode="extended")
self.buffers.append(mentions) self.buffers.append(mentions)
self.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'dm': elif i == 'dm':
dm = twitterBuffers.directMessagesController(self.view.nb, "get_direct_messages", "direct_messages", session, session.db["user_name"], bufferType="dmPanel", compose_func="compose_direct_message", sound="dm_received.ogg", full_text=True, items="events") dm = twitterBuffers.directMessagesController(self.view.nb, "list_direct_messages", "direct_messages", session, session.db["user_name"], bufferType="dmPanel", compose_func="compose_direct_message", sound="dm_received.ogg", full_text=True, items="events")
self.buffers.append(dm) self.buffers.append(dm)
self.view.insert_buffer(dm.buffer, name=_(u"Direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(dm.buffer, name=_(u"Direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'sent_dm': elif i == 'sent_dm':
@ -320,62 +320,62 @@ class Controller(object):
self.buffers.append(sent_dm) self.buffers.append(sent_dm)
self.view.insert_buffer(sent_dm.buffer, name=_(u"Sent direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(sent_dm.buffer, name=_(u"Sent direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'sent_tweets': elif i == 'sent_tweets':
sent_tweets = twitterBuffers.baseBufferController(self.view.nb, "get_user_timeline", "sent_tweets", session, session.db["user_name"], screen_name=session.db["user_name"], tweet_mode="extended") sent_tweets = twitterBuffers.baseBufferController(self.view.nb, "user_timeline", "sent_tweets", session, session.db["user_name"], screen_name=session.db["user_name"], tweet_mode="extended")
self.buffers.append(sent_tweets) self.buffers.append(sent_tweets)
self.view.insert_buffer(sent_tweets.buffer, name=_(u"Sent tweets"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(sent_tweets.buffer, name=_(u"Sent tweets"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'favorites': elif i == 'favorites':
favourites = twitterBuffers.baseBufferController(self.view.nb, "get_favorites", "favourites", session, session.db["user_name"], sound="favourite.ogg", tweet_mode="extended") favourites = twitterBuffers.baseBufferController(self.view.nb, "favorites", "favourites", session, session.db["user_name"], sound="favourite.ogg", tweet_mode="extended")
self.buffers.append(favourites) self.buffers.append(favourites)
self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'followers': elif i == 'followers':
followers = twitterBuffers.peopleBufferController(self.view.nb, "get_followers_list", "followers", session, session.db["user_name"], sound="update_followers.ogg", screen_name=session.db["user_name"]) followers = twitterBuffers.peopleBufferController(self.view.nb, "followers", "followers", session, session.db["user_name"], sound="update_followers.ogg", screen_name=session.db["user_name"])
self.buffers.append(followers) self.buffers.append(followers)
self.view.insert_buffer(followers.buffer, name=_(u"Followers"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(followers.buffer, name=_(u"Followers"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'friends': elif i == 'friends':
friends = twitterBuffers.peopleBufferController(self.view.nb, "get_friends_list", "friends", session, session.db["user_name"], screen_name=session.db["user_name"]) friends = twitterBuffers.peopleBufferController(self.view.nb, "friends", "friends", session, session.db["user_name"], screen_name=session.db["user_name"])
self.buffers.append(friends) self.buffers.append(friends)
self.view.insert_buffer(friends.buffer, name=_(u"Friends"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(friends.buffer, name=_(u"Friends"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'blocks': elif i == 'blocks':
blocks = twitterBuffers.peopleBufferController(self.view.nb, "list_blocks", "blocked", session, session.db["user_name"]) blocks = twitterBuffers.peopleBufferController(self.view.nb, "blocks", "blocked", session, session.db["user_name"])
self.buffers.append(blocks) self.buffers.append(blocks)
self.view.insert_buffer(blocks.buffer, name=_(u"Blocked users"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(blocks.buffer, name=_(u"Blocked users"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'muted': elif i == 'muted':
muted = twitterBuffers.peopleBufferController(self.view.nb, "list_mutes", "muted", session, session.db["user_name"]) muted = twitterBuffers.peopleBufferController(self.view.nb, "mutes", "muted", session, session.db["user_name"])
self.buffers.append(muted) self.buffers.append(muted)
self.view.insert_buffer(muted.buffer, name=_(u"Muted users"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(muted.buffer, name=_(u"Muted users"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
timelines = baseBuffers.emptyPanel(self.view.nb, "timelines", session.db["user_name"]) timelines = baseBuffers.emptyPanel(self.view.nb, "timelines", session.db["user_name"])
self.buffers.append(timelines) self.buffers.append(timelines)
self.view.insert_buffer(timelines.buffer , name=_(u"Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(timelines.buffer , name=_(u"Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["timelines"]: for i in session.settings["other_buffers"]["timelines"]:
tl = twitterBuffers.baseBufferController(self.view.nb, "get_user_timeline", "%s-timeline" % (i,), session, session.db["user_name"], sound="tweet_timeline.ogg", bufferType=None, user_id=i, tweet_mode="extended") tl = twitterBuffers.baseBufferController(self.view.nb, "user_timeline", "%s-timeline" % (i,), session, session.db["user_name"], sound="tweet_timeline.ogg", bufferType=None, user_id=i, tweet_mode="extended")
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(i,), pos=self.view.search("timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(i,), pos=self.view.search("timelines", session.db["user_name"]))
favs_timelines = baseBuffers.emptyPanel(self.view.nb, "favs_timelines", session.db["user_name"]) favs_timelines = baseBuffers.emptyPanel(self.view.nb, "favs_timelines", session.db["user_name"])
self.buffers.append(favs_timelines) self.buffers.append(favs_timelines)
self.view.insert_buffer(favs_timelines.buffer , name=_(u"Likes timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(favs_timelines.buffer , name=_(u"Likes timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["favourites_timelines"]: for i in session.settings["other_buffers"]["favourites_timelines"]:
tl = twitterBuffers.baseBufferController(self.view.nb, "get_favorites", "%s-favorite" % (i,), session, session.db["user_name"], bufferType=None, sound="favourites_timeline_updated.ogg", user_id=i, tweet_mode="extended") tl = twitterBuffers.baseBufferController(self.view.nb, "favorites", "%s-favorite" % (i,), session, session.db["user_name"], bufferType=None, sound="favourites_timeline_updated.ogg", user_id=i, tweet_mode="extended")
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Likes for {}").format(i,), pos=self.view.search("favs_timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Likes for {}").format(i,), pos=self.view.search("favs_timelines", session.db["user_name"]))
followers_timelines = baseBuffers.emptyPanel(self.view.nb, "followers_timelines", session.db["user_name"]) followers_timelines = baseBuffers.emptyPanel(self.view.nb, "followers_timelines", session.db["user_name"])
self.buffers.append(followers_timelines) self.buffers.append(followers_timelines)
self.view.insert_buffer(followers_timelines.buffer , name=_(u"Followers' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(followers_timelines.buffer , name=_(u"Followers' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["followers_timelines"]: for i in session.settings["other_buffers"]["followers_timelines"]:
tl = twitterBuffers.peopleBufferController(self.view.nb, "get_followers_list", "%s-followers" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i) tl = twitterBuffers.peopleBufferController(self.view.nb, "followers", "%s-followers" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i)
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Followers for {}").format(i,), pos=self.view.search("followers_timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Followers for {}").format(i,), pos=self.view.search("followers_timelines", session.db["user_name"]))
friends_timelines = baseBuffers.emptyPanel(self.view.nb, "friends_timelines", session.db["user_name"]) friends_timelines = baseBuffers.emptyPanel(self.view.nb, "friends_timelines", session.db["user_name"])
self.buffers.append(friends_timelines) self.buffers.append(friends_timelines)
self.view.insert_buffer(friends_timelines.buffer , name=_(u"Friends' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(friends_timelines.buffer , name=_(u"Friends' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["friends_timelines"]: for i in session.settings["other_buffers"]["friends_timelines"]:
tl = twitterBuffers.peopleBufferController(self.view.nb, "get_friends_list", "%s-friends" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i) tl = twitterBuffers.peopleBufferController(self.view.nb, "friends", "%s-friends" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i)
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Friends for {}").format(i,), pos=self.view.search("friends_timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Friends for {}").format(i,), pos=self.view.search("friends_timelines", session.db["user_name"]))
lists = baseBuffers.emptyPanel(self.view.nb, "lists", session.db["user_name"]) lists = baseBuffers.emptyPanel(self.view.nb, "lists", session.db["user_name"])
self.buffers.append(lists) self.buffers.append(lists)
self.view.insert_buffer(lists.buffer , name=_(u"Lists"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(lists.buffer , name=_(u"Lists"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["lists"]: for i in session.settings["other_buffers"]["lists"]:
tl = twitterBuffers.listBufferController(self.view.nb, "get_list_statuses", "%s-list" % (i,), session, session.db["user_name"], bufferType=None, sound="list_tweet.ogg", list_id=utils.find_list(i, session.db["lists"]), tweet_mode="extended") tl = twitterBuffers.listBufferController(self.view.nb, "list_timeline", "%s-list" % (i,), session, session.db["user_name"], bufferType=None, sound="list_tweet.ogg", list_id=utils.find_list(i, session.db["lists"]), tweet_mode="extended")
session.lists.append(tl) session.lists.append(tl)
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(i), pos=self.view.search("lists", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(i), pos=self.view.search("lists", session.db["user_name"]))

View File

@ -39,41 +39,41 @@ chars = "abcdefghijklmnopqrstuvwxyz"
def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=None): 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.""" """ 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": 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: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else: else:
ts = tweet["created_at"] ts = tweet.created_at
if "message" in tweet: if hasattr(tweet, "message"):
value = "message" value = "message"
elif "full_text" in tweet: elif hasattr(tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
if "retweeted_status" in tweet and value != "message": if hasattr(tweet, "retweeted_status") and value != "message":
text = StripChars(tweet["retweeted_status"][value]) text = StripChars(getattr(tweet.retweeted_status, value))
else: else:
text = StripChars(tweet[value]) text = StripChars(getattr(tweet, value))
if show_screen_names: if show_screen_names:
user = tweet["user"]["screen_name"] user = tweet.user.screen_name
else: else:
user = tweet["user"]["name"] user = tweet.user.name
source = re.sub(r"(?s)<.*?>", "", tweet["source"]) source = re.sub(r"(?s)<.*?>", "", tweet.source)
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
if ("message" in tweet) == False and tweet["retweeted_status"]["is_quote_status"] == False: if (hasattr(tweet, "message")) == False and tweet.retweeted_status.is_quote_status == False:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text) text = "RT @%s: %s" % (tweet.retweeted_status.user.screen_name, text)
elif tweet["retweeted_status"]["is_quote_status"]: elif tweet.retweeted_status.is_quote_status:
text = "%s" % (text) text = "%s" % (text)
else: else:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text) text = "RT @%s: %s" % (tweet.retweeted_status.user.screen_name, text)
if ("message" in tweet) == False: if not hasattr(tweet, "message"):
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
text = utils.expand_urls(text, tweet["retweeted_status"]["entities"]) text = utils.expand_urls(text, tweet.retweeted_status.entities)
else: else:
text = utils.expand_urls(text, tweet["entities"]) text = utils.expand_urls(text, tweet.entities)
if config.app['app-settings']['handle_longtweets']: pass if config.app['app-settings']['handle_longtweets']: pass
return [user+", ", text, ts+", ", source] 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": if system == "Windows":
# Let's remove the last 3 digits in the timestamp string. # 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. # 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: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else: else:
ts = item["created_timestamp"] ts = item.created_timestamp
text = StripChars(item["message_create"]["message_data"]["text"]) text = StripChars(item.message_create.message_data.text)
source = "DM" source = "DM"
sender = session.get_user(item["message_create"]["sender_id"]) sender = session.get_user(item.message_create.sender_id)
if db["user_name"] == sender["screen_name"]: if db["user_name"] == sender.screen_name:
if show_screen_names: 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: 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: else:
if show_screen_names: if show_screen_names:
user = sender["screen_name"] user = sender.screen_name
else: else:
user = sender["name"] user = sender.name
if text[-1] in chars: text=text+"." 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] return [user+", ", text, ts+", ", source]
def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False, session=None): 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.""" """ 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 hasattr(quoted_tweet, "retweeted_status"):
if "full_text" in quoted_tweet["retweeted_status"]: if hasattr(quoted_tweet.retweeted_status, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
text = StripChars(quoted_tweet["retweeted_status"][value]) text = StripChars(getattr(quoted_tweet.retweeted_status, value))
else: else:
if "full_text" in quoted_tweet: if hasattr(quoted_tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
text = StripChars(quoted_tweet[value]) text = StripChars(getattr(quoted_tweet, value))
if show_screen_names: if show_screen_names:
quoting_user = quoted_tweet["user"]["screen_name"] quoting_user = quoted_tweet.user.screen_name
else: else:
quoting_user = quoted_tweet["user"]["name"] quoting_user = quoted_tweet.user.name
source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"]) source = re.sub(r"(?s)<.*?>", "", quoted_tweet.source)
if "retweeted_status" in quoted_tweet: if hasattr(quoted_tweet, "retweeted_status"):
text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], text) text = "rt @%s: %s" % (quoted_tweet.retweeted_status.user.screen_name, text)
if text[-1] in chars: text=text+"." if text[-1] in chars: text=text+"."
original_user = original_tweet["user"]["screen_name"] original_user = original_tweet.user.screen_name
if "message" in original_tweet: if hasattr(original_tweet, "message"):
original_text = original_tweet["message"] original_text = original_tweet.message
elif "full_text" in original_tweet: elif hasattr(original_tweet, "full_text"):
original_text = StripChars(original_tweet["full_text"]) original_text = StripChars(original_tweet.full_text)
else: else:
original_text = StripChars(original_tweet["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.message = _(u"{0}. Quoted tweet from @{1}: {2}").format( text, original_user, original_text)
quoted_tweet = tweets.clear_url(quoted_tweet) 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 return quoted_tweet
def compose_followers_list(tweet, db, relative_times=True, show_screen_names=False, session=None): def compose_followers_list(tweet, db, relative_times=True, show_screen_names=False, session=None):
if system == "Windows": 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: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else: else:
ts = tweet["created_at"] ts = tweet.created_at
if "status" in tweet: if hasattr(tweet, "status"):
if len(tweet["status"]) > 4 and system == "Windows": 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") original_date2 = arrow.get(tweet.status.created_at, "ddd MMM D H:m:s Z YYYY", locale="en")
if relative_times: if relative_times:
ts2 = original_date2.humanize(locale=languageHandler.curLang[:2]) ts2 = original_date2.humanize(locale=languageHandler.curLang[:2])
else: else:
@ -161,14 +161,14 @@ def compose_followers_list(tweet, db, relative_times=True, show_screen_names=Fal
ts2 = _("Unavailable") ts2 = _("Unavailable")
else: else:
ts2 = _("Unavailable") 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): def compose_list(list):
name = list["name"] name = list.name
if list["description"] == None: description = _(u"No description available") if list.description == None: description = _(u"No description available")
else: description = list["description"] else: description = list.description
user = list["user"]["name"] user = list.user.name
members = str(list["member_count"]) members = str(list.member_count)
if list["mode"] == "private": status = _(u"private") if list.mode == "private": status = _(u"private")
else: status = _(u"public") else: status = _(u"public")
return [name, description, user, members, status] return [name, description, user, members, status]

View File

@ -40,24 +40,24 @@ class Session(base.baseSession):
self.db["users"] = {} self.db["users"] = {}
if ignore_older and len(self.db[name]) > 0: if ignore_older and len(self.db[name]) > 0:
if self.settings["general"]["reverse_timelines"] == False: if self.settings["general"]["reverse_timelines"] == False:
last_id = self.db[name][0]["id"] last_id = self.db[name][0].id
else: else:
last_id = self.db[name][-1]["id"] last_id = self.db[name][-1].id
for i in data: for i in data:
if ignore_older and last_id != None: if ignore_older and last_id != None:
if i["id"] < last_id: if i.id < last_id:
log.error("Ignoring an older tweet... Last id: {0}, tweet id: {1}".format(last_id, i["id"])) log.error("Ignoring an older tweet... Last id: {0}, tweet id: {1}".format(last_id, i.id))
continue continue
if utils.find_item(i["id"], self.db[name]) == None and utils.is_allowed(i, self.settings, name) == True: if utils.find_item(i.id, self.db[name]) == None and utils.is_allowed(i, self.settings, name) == True:
i = self.check_quoted_status(i) i = self.check_quoted_status(i)
i = self.check_long_tweet(i) i = self.check_long_tweet(i)
if i == False: continue if i == False: continue
if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i)
else: self.db[name].insert(0, i) else: self.db[name].insert(0, i)
num = num+1 num = num+1
if ("user" in i) == True: if hasattr(i, "user"):
if (i["user"]["id"] in self.db["users"]) == False: if (i.user.id in self.db["users"]) == False:
self.db["users"][i["user"]["id"]] = i["user"] self.db["users"][i.user.id] = i.user
return num return num
def order_cursored_buffer(self, name, data): def order_cursored_buffer(self, name, data):
@ -74,7 +74,7 @@ class Session(base.baseSession):
self.db[name] = {} self.db[name] = {}
self.db[name]["items"] = [] self.db[name]["items"] = []
for i in data: for i in data:
if utils.find_item(i["id"], self.db[name]["items"]) == None: if utils.find_item(i.id, self.db[name]["items"]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db[name]["items"].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db[name]["items"].append(i)
else: self.db[name]["items"].insert(0, i) else: self.db[name]["items"].insert(0, i)
num = num+1 num = num+1
@ -90,13 +90,13 @@ class Session(base.baseSession):
self.db["direct_messages"] = {} self.db["direct_messages"] = {}
self.db["direct_messages"]["items"] = [] self.db["direct_messages"]["items"] = []
for i in data: for i in data:
if i["message_create"]["sender_id"] == self.db["user_id"]: if i.message_create.sender_id == self.db["user_id"]:
if "sent_direct_messages" in self.db and utils.find_item(i["id"], self.db["sent_direct_messages"]["items"]) == None: if "sent_direct_messages" in self.db and utils.find_item(i.id, self.db["sent_direct_messages"]["items"]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db["sent_direct_messages"]["items"].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db["sent_direct_messages"]["items"].append(i)
else: self.db["sent_direct_messages"]["items"].insert(0, i) else: self.db["sent_direct_messages"]["items"].insert(0, i)
sent = sent+1 sent = sent+1
else: else:
if utils.find_item(i["id"], self.db["direct_messages"]["items"]) == None: if utils.find_item(i.id, self.db["direct_messages"]["items"]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db["direct_messages"]["items"].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db["direct_messages"]["items"].append(i)
else: self.db["direct_messages"]["items"].insert(0, i) else: self.db["direct_messages"]["items"].insert(0, i)
incoming = incoming+1 incoming = incoming+1
@ -229,15 +229,15 @@ class Session(base.baseSession):
def search(self, name, *args, **kwargs): def search(self, name, *args, **kwargs):
""" Search in twitter, passing args and kwargs as arguments to the Twython function.""" """ Search in twitter, passing args and kwargs as arguments to the Twython function."""
tl = self.twitter.search(*args, **kwargs) tl = self.twitter.search(*args, **kwargs)
tl["statuses"].reverse() tl.reverse()
return tl["statuses"] return tl
# @_require_login # @_require_login
def get_favourites_timeline(self, name, *args, **kwargs): def get_favourites_timeline(self, name, *args, **kwargs):
""" Gets favourites for the authenticated user or a friend or follower. """ Gets favourites for the authenticated user or a friend or follower.
name str: Name for storage in the database. name str: Name for storage in the database.
args and kwargs are passed directly to the Twython function.""" args and kwargs are passed directly to the Twython function."""
tl = self.call_paged("get_favorites", *args, **kwargs) tl = self.call_paged("favorites", *args, **kwargs)
return self.order_buffer(name, tl) return self.order_buffer(name, tl)
def call_paged(self, update_function, *args, **kwargs): def call_paged(self, update_function, *args, **kwargs):
@ -251,8 +251,8 @@ class Session(base.baseSession):
data = getattr(self.twitter, update_function)(count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs) data = getattr(self.twitter, update_function)(count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs)
results.extend(data) results.extend(data)
for i in range(0, max): for i in range(0, max):
if i == 0: max_id = results[-1]["id"] if i == 0: max_id = results[-1].id
else: max_id = results[0]["id"] else: max_id = results[0].id
data = getattr(self.twitter, update_function)(max_id=max_id, count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs) data = getattr(self.twitter, update_function)(max_id=max_id, count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs)
results.extend(data) results.extend(data)
results.reverse() results.reverse()
@ -357,25 +357,25 @@ class Session(base.baseSession):
def get_quoted_tweet(self, tweet): def get_quoted_tweet(self, tweet):
""" Process a tweet and extract all information related to the quote.""" """ Process a tweet and extract all information related to the quote."""
quoted_tweet = tweet quoted_tweet = tweet
if "full_text" in tweet: if hasattr(tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
quoted_tweet[value] = utils.expand_urls(quoted_tweet[value], quoted_tweet["entities"]) setattr(quoted_tweet, value)(utils.expand_urls(getattr(quoted_tweet, value), quoted_tweet.entities))
if "quoted_status" in quoted_tweet: if hasattr(quoted_tweet, "quoted_status"):
original_tweet = quoted_tweet["quoted_status"] original_tweet = quoted_tweet.quoted_status
elif "retweeted_status" in quoted_tweet and "quoted_status" in quoted_tweet["retweeted_status"]: elif hasattr(quoted_tweet, "retweeted_status") and hasattr(quoted_tweet.retweeted_status, "quoted_status"):
original_tweet = quoted_tweet["retweeted_status"]["quoted_status"] original_tweet = quoted_tweet.retweeted_status.quoted_status
else: else:
return quoted_tweet return quoted_tweet
original_tweet = self.check_long_tweet(original_tweet) original_tweet = self.check_long_tweet(original_tweet)
if "full_text" in original_tweet: if hasattr(original_tweet, "full_text"):
value = "full_text" value = "full_text"
elif "message" in original_tweet: elif hasattr(original_tweet, "message"):
value = "message" value = "message"
else: else:
value = "text" value = "text"
original_tweet[value] = utils.expand_urls(original_tweet[value], original_tweet["entities"]) setattr(original_tweet, value)(utils.expand_urls(getattr(original_tweet, value), original_tweet.entities))
return compose.compose_quoted_tweet(quoted_tweet, original_tweet) return compose.compose_quoted_tweet(quoted_tweet, original_tweet)
def check_long_tweet(self, tweet): def check_long_tweet(self, tweet):
@ -385,22 +385,22 @@ class Session(base.baseSession):
long = twishort.is_long(tweet) long = twishort.is_long(tweet)
if long != False and config.app["app-settings"]["handle_longtweets"]: if long != False and config.app["app-settings"]["handle_longtweets"]:
message = twishort.get_full_text(long) message = twishort.get_full_text(long)
if "quoted_status" in tweet: if hasattr(tweet, "quoted_status"):
tweet["quoted_status"]["message"] = message tweet.quoted_status.message = message
if tweet["quoted_status"]["message"] == False: return False if tweet.quoted_status.message == False: return False
tweet["quoted_status"]["twishort"] = True tweet.quoted_status.twishort = True
for i in tweet["quoted_status"]["entities"]["user_mentions"]: for i in tweet.quoted_status.entities.user_mentions:
if "@%s" % (i["screen_name"]) not in tweet["quoted_status"]["message"] and i["screen_name"] != tweet["user"]["screen_name"]: if "@%s" % (i.screen_name) not in tweet.quoted_status.message and i.screen_name != tweet.user.screen_name:
if "retweeted_status" in tweet["quoted_status"] and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]: if hasattr(tweet["quoted_status"], "retweeted_status") and tweet.retweeted_status.user.screen_name == i.screen_name:
continue continue
tweet["quoted_status"]["message"] = u"@%s %s" % (i["screen_name"], tweet["message"]) tweet.quoted_status.message = u"@%s %s" % (i.screen_name, tweet.message)
else: else:
tweet["message"] = message tweet.message = message
if tweet["message"] == False: return False if tweet.message == False: return False
tweet["twishort"] = True tweet.twishort = True
for i in tweet["entities"]["user_mentions"]: for i in tweet.entities.user_mentions:
if "@%s" % (i["screen_name"]) not in tweet["message"] and i["screen_name"] != tweet["user"]["screen_name"]: if "@%s" % (i.screen_name) not in tweet.message and i.screen_name != tweet.user.screen_name:
if "retweeted_status" in tweet and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]: if hasattr(tweet, "retweeted_status") and tweet.retweeted_status.user.screen_name == i.screen_name:
continue continue
return tweet return tweet

View File

@ -28,35 +28,35 @@ def find_urls_in_text(text):
def find_urls (tweet): def find_urls (tweet):
urls = [] urls = []
# Let's add URLS from tweet entities. # Let's add URLS from tweet entities.
if "message_create" in tweet: if hasattr(tweet, "message_create"):
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet.message_create.message_data.entities
else: else:
entities = tweet["entities"] entities = tweet.entities
for i in entities["urls"]: for i in entities.urls:
if i["expanded_url"] not in urls: if i.expanded_url not in urls:
urls.append(i["expanded_url"]) urls.append(i.expanded_url)
if "quoted_status" in tweet: if hasattr(tweet, "quoted_status"):
for i in tweet["quoted_status"]["entities"]["urls"]: for i in tweet.quoted_status.entities.urls:
if i["expanded_url"] not in urls: if i.expanded_url not in urls:
urls.append(i["expanded_url"]) urls.append(i.expanded_url)
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
for i in tweet["retweeted_status"]["entities"]["urls"]: for i in tweet.retweeted_status.entities.urls:
if i["expanded_url"] not in urls: if i.expanded_url not in urls:
urls.append(i["expanded_url"]) urls.append(i.expanded_url)
if "quoted_status" in tweet["retweeted_status"]: if hasattr(tweet["retweeted_status"], "quoted_status"):
for i in tweet["retweeted_status"]["quoted_status"]["entities"]["urls"]: for i in tweet.retweeted_status.quoted_status.entities.urls:
if i["expanded_url"] not in urls: if i.expanded_url not in urls:
urls.append(i["expanded_url"]) urls.append(i.expanded_url)
if "message" in tweet: if hasattr(tweet, "message"):
i = "message" i = "message"
elif "full_text" in tweet: elif hasattr(tweet, "full_text"):
i = "full_text" i = "full_text"
else: else:
i = "text" i = "text"
if "message_create" in tweet: if hasattr(tweet, "message_create"):
extracted_urls = find_urls_in_text(tweet["message_create"]["message_data"]["text"]) extracted_urls = find_urls_in_text(tweet.message_create.message_data.text)
else: else:
extracted_urls = find_urls_in_text(tweet[i]) extracted_urls = find_urls_in_text(getattr(tweet, i))
# Don't include t.co links (mostly they are photos or shortened versions of already added URLS). # Don't include t.co links (mostly they are photos or shortened versions of already added URLS).
for i in extracted_urls: for i in extracted_urls:
if i not in urls and "https://t.co" not in i: if i not in urls and "https://t.co" not in i:
@ -65,70 +65,70 @@ def find_urls (tweet):
def find_item(id, listItem): def find_item(id, listItem):
for i in range(0, len(listItem)): for i in range(0, len(listItem)):
if listItem[i]["id"] == id: return i if listItem[i].id == id: return i
return None return None
def find_list(name, lists): def find_list(name, lists):
for i in range(0, len(lists)): for i in range(0, len(lists)):
if lists[i]["name"] == name: return lists[i]["id"] if lists[i].name == name: return lists[i].id
def is_audio(tweet): def is_audio(tweet):
try: try:
if len(find_urls(tweet)) < 1: if len(find_urls(tweet)) < 1:
return False return False
if "message_create" in tweet: if hasattr(tweet, "message_create"):
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet.message_create.message_data.entities
else: else:
entities = tweet["entities"] entities = tweet.entities
if len(entities["hashtags"]) > 0: if len(entities.hashtags) > 0:
for i in entities["hashtags"]: for i in entities.hashtags:
if i["text"] == "audio": if i.text == "audio":
return True return True
except IndexError: except IndexError:
print(tweet["entities"]["hashtags"]) print(tweet.entities.hashtags)
log.exception("Exception while executing is_audio hashtag algorithm") log.exception("Exception while executing is_audio hashtag algorithm")
def is_geocoded(tweet): def is_geocoded(tweet):
if "coordinates" in tweet and tweet["coordinates"] != None: if hasattr(tweet, "coordinates") and tweet.coordinates != None:
return True return True
def is_media(tweet): def is_media(tweet):
if "message_create" in tweet: if hasattr(tweet, "message_create"):
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet.message_create.message_data.entities
else: else:
entities = tweet["entities"] entities = tweet.entities
if ("media" in entities) == False: if not hasattr(entities, media):
return False return False
for i in entities["media"]: for i in entities.media:
if "type" in i and i["type"] == "photo": if hasattr(i, "type") and i.type == "photo":
return True return True
return False return False
def get_all_mentioned(tweet, conf, field="screen_name"): def get_all_mentioned(tweet, conf, field="screen_name"):
""" Gets all users that have been mentioned.""" """ Gets all users that have been mentioned."""
results = [] results = []
for i in tweet["entities"]["user_mentions"]: for i in tweet.entities.user_mentions:
if i["screen_name"] != conf["user_name"] and i["screen_name"] != tweet["user"]["screen_name"]: if i.screen_name != conf["user_name"] and i.screen_name != tweet.user.screen_name:
if i[field] not in results: if getattr(i, field) not in results:
results.append(i[field]) results.append(getattr(i, field))
return results return results
def get_all_users(tweet, conf): def get_all_users(tweet, conf):
string = [] string = []
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
string.append(tweet["user"]["screen_name"]) string.append(tweet.user.screen_name)
tweet = tweet["retweeted_status"] tweet = tweet.retweeted_status
if "sender" in tweet: if hasattr(tweet, "sender"):
string.append(tweet["sender"]["screen_name"]) string.append(tweet.sender.screen_name)
else: else:
if tweet["user"]["screen_name"] != conf["user_name"]: if tweet.user.screen_name != conf["user_name"]:
string.append(tweet["user"]["screen_name"]) string.append(tweet.user.screen_name)
for i in tweet["entities"]["user_mentions"]: for i in tweet.entities.user_mentions:
if i["screen_name"] != conf["user_name"] and i["screen_name"] != tweet["user"]["screen_name"]: if i.screen_name != conf["user_name"] and i.screen_name != tweet.user.screen_name:
if i["screen_name"] not in string: if i.screen_name not in string:
string.append(i["screen_name"]) string.append(i.screen_name)
if len(string) == 0: if len(string) == 0:
string.append(tweet["user"]["screen_name"]) string.append(tweet.user.screen_name)
return string return string
def if_user_exists(twitter, user): def if_user_exists(twitter, user):
@ -143,24 +143,25 @@ def if_user_exists(twitter, user):
def is_allowed(tweet, settings, buffer_name): def is_allowed(tweet, settings, buffer_name):
clients = settings["twitter"]["ignored_clients"] clients = settings["twitter"]["ignored_clients"]
if "sender" in tweet: return True if hasattr(tweet, "sender"): return True
allowed = True allowed = True
tweet_data = {} tweet_data = {}
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
tweet_data["retweet"] = True tweet_data["retweet"] = True
if tweet["in_reply_to_status_id_str"] != None: if tweet.in_reply_to_status_id_str != None:
tweet_data["reply"] = True tweet_data["reply"] = True
if "quoted_status" in tweet: if hasattr(tweet, "quoted_status"):
tweet_data["quote"] = True tweet_data["quote"] = True
if "retweeted_status" in tweet: tweet = tweet["retweeted_status"] if hasattr(tweet, "retweeted_status"):
source = re.sub(r"(?s)<.*?>", "", tweet["source"]) tweet = tweet.retweeted_status
source = re.sub(r"(?s)<.*?>", "", tweet.source)
for i in clients: for i in clients:
if i.lower() == source.lower(): if i.lower() == source.lower():
return False return False
return filter_tweet(tweet, tweet_data, settings, buffer_name) return filter_tweet(tweet, tweet_data, settings, buffer_name)
def filter_tweet(tweet, tweet_data, settings, buffer_name): def filter_tweet(tweet, tweet_data, settings, buffer_name):
if "full_text" in tweet: if hasattr(tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
@ -188,16 +189,16 @@ def filter_tweet(tweet, tweet_data, settings, buffer_name):
if allow_replies == "False" and "reply" in tweet_data: if allow_replies == "False" and "reply" in tweet_data:
return False return False
if word != "" and settings["filters"][i]["if_word_exists"]: if word != "" and settings["filters"][i]["if_word_exists"]:
if word in tweet[value]: if word in getattr(tweet, value):
return False return False
elif word != "" and settings["filters"][i]["if_word_exists"] == False: elif word != "" and settings["filters"][i]["if_word_exists"] == False:
if word not in tweet[value]: if word not in getattr(tweet, value):
return False return False
if settings["filters"][i]["in_lang"] == "True": if settings["filters"][i]["in_lang"] == "True":
if tweet["lang"] not in settings["filters"][i]["languages"]: if getattr(tweet, lang) not in settings["filters"][i]["languages"]:
return False return False
elif settings["filters"][i]["in_lang"] == "False": elif settings["filters"][i]["in_lang"] == "False":
if tweet["lang"] in settings["filters"][i]["languages"]: if tweet.lang in settings["filters"][i]["languages"]:
return False return False
return True return True
@ -213,7 +214,7 @@ def twitter_error(error):
def expand_urls(text, entities): def expand_urls(text, entities):
""" Expand all URLS present in text with information found in entities""" """ Expand all URLS present in text with information found in entities"""
urls = find_urls_in_text(text) urls = find_urls_in_text(text)
for url in entities["urls"]: for url in entities.urls:
if url["url"] in text: if url.url in text:
text = text.replace(url["url"], url["expanded_url"]) text = text.replace(url.url, url.expanded_url)
return text return text