Added date and time wen displaying tweets and dm's

This commit is contained in:
Manuel Cortez 2018-09-30 14:39:59 -05:00
parent 74e020c090
commit c85c478595
4 changed files with 41 additions and 11 deletions

View File

@ -2,6 +2,7 @@
## changes in this version ## changes in this version
* When displaying tweets or direct messages, a new field has been added to show the date when the item has been posted to Twitter.
* Added support for deleting direct messages by using the new Twitter API methods. * Added support for deleting direct messages by using the new Twitter API methods.
* When quoting a retweet, the quote will be made to the original tweet instead of the retweet. * When quoting a retweet, the quote will be made to the original tweet instead of the retweet.
* If the sent direct messages buffer is hidden, TWBlue should keep loading everything as expected. ([#246](https://github.com/manuelcortez/TWBlue/issues/246)) * If the sent direct messages buffer is hidden, TWBlue should keep loading everything as expected. ([#246](https://github.com/manuelcortez/TWBlue/issues/246))

View File

@ -4,6 +4,7 @@ system = platform.system()
import application import application
import requests import requests
import youtube_utils import youtube_utils
import arrow
if system == "Windows": if system == "Windows":
from update import updater from update import updater
from wxUI import (view, dialogs, commonMessageDialogs, sysTrayIcon) from wxUI import (view, dialogs, commonMessageDialogs, sysTrayIcon)
@ -792,14 +793,17 @@ class Controller(object):
def view_item(self, *args, **kwargs): def view_item(self, *args, **kwargs):
buffer = self.get_current_buffer() buffer = self.get_current_buffer()
if buffer.type == "baseBuffer" or buffer.type == "favourites_timeline" or buffer.type == "list" or buffer.type == "search": if buffer.type == "account" or buffer.type == "empty":
tweet, tweetsList = buffer.get_full_tweet()
msg = messages.viewTweet(tweet, tweetsList)
elif buffer.type == "account" or buffer.type == "empty":
return return
elif buffer.name == "sent_tweets": elif buffer.type == "baseBuffer" or buffer.type == "favourites_timeline" or buffer.type == "list" or buffer.type == "search":
tweet, tweetsList = buffer.get_full_tweet() tweet, tweetsList = buffer.get_full_tweet()
msg = messages.viewTweet(tweet, tweetsList) msg = messages.viewTweet(tweet, tweetsList, utc_offset=buffer.session.db["utc_offset"])
elif buffer.type == "dm":
non_tweet = buffer.get_formatted_message()
item = buffer.get_right_tweet()
original_date = arrow.get(item["created_timestamp"][:-3])
date = original_date.replace(seconds=buffer.session.db["utc_offset"]).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
msg = messages.viewTweet(non_tweet, [], False, date=date)
else: else:
non_tweet = buffer.get_formatted_message() non_tweet = buffer.get_formatted_message()
msg = messages.viewTweet(non_tweet, [], False) msg = messages.viewTweet(non_tweet, [], False)

View File

@ -2,6 +2,8 @@
import re import re
import platform import platform
import attach import attach
import arrow
import languageHandler
system = platform.system() system = platform.system()
import widgetUtils import widgetUtils
import output import output
@ -193,7 +195,7 @@ class dm(basicTweet):
c.show_menu("dm") c.show_menu("dm")
class viewTweet(basicTweet): class viewTweet(basicTweet):
def __init__(self, tweet, tweetList, is_tweet=True): def __init__(self, tweet, tweetList, is_tweet=True, utc_offset=0, date=""):
""" This represents a tweet displayer. However it could be used for showing something wich is not a tweet, like a direct message or an event. """ This represents a tweet displayer. However it could be used for showing something wich is not a tweet, like a direct message or an event.
param tweet: A dictionary that represents a full tweet or a string for non-tweets. param tweet: A dictionary that represents a full tweet or a string for non-tweets.
param tweetList: If is_tweet is set to True, this could be a list of quoted tweets. param tweetList: If is_tweet is set to True, this could be a list of quoted tweets.
@ -229,6 +231,8 @@ class viewTweet(basicTweet):
favs_count = str(tweet["favorite_count"]) favs_count = str(tweet["favorite_count"])
# Gets the client from where this tweet was made. # Gets the client from where this tweet was made.
source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8"))) source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8")))
original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en")
date = original_date.replace(seconds=utc_offset).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
if text == "": if text == "":
if tweet.has_key("message"): if tweet.has_key("message"):
value = "message" value = "message"
@ -250,13 +254,13 @@ class viewTweet(basicTweet):
for z in tweet["retweeted_status"]["extended_entities"]["media"]: for z in tweet["retweeted_status"]["extended_entities"]["media"]:
if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: if z.has_key("ext_alt_text") and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
self.message = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8")) self.message = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8"), date)
self.message.set_title(len(text)) self.message.set_title(len(text))
[self.message.set_image_description(i) for i in image_description] [self.message.set_image_description(i) for i in image_description]
else: else:
self.title = _(u"View item") self.title = _(u"View item")
text = tweet text = tweet
self.message = message.viewNonTweet(text) self.message = message.viewNonTweet(text, date)
widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck) widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate) widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate)
if self.contain_urls() == True: if self.contain_urls() == True:

View File

@ -298,7 +298,7 @@ class viewTweet(widgetUtils.BaseDialog):
def set_title(self, lenght): def set_title(self, lenght):
self.SetTitle(_(u"Tweet - %i characters ") % (lenght,)) self.SetTitle(_(u"Tweet - %i characters ") % (lenght,))
def __init__(self, text, rt_count, favs_count,source, *args, **kwargs): def __init__(self, text, rt_count, favs_count, source, date="", *args, **kwargs):
super(viewTweet, self).__init__(None, size=(850,850)) super(viewTweet, self).__init__(None, size=(850,850))
panel = wx.Panel(self) panel = wx.Panel(self)
label = wx.StaticText(panel, -1, _(u"Tweet")) label = wx.StaticText(panel, -1, _(u"Tweet"))
@ -339,11 +339,21 @@ class viewTweet(widgetUtils.BaseDialog):
sourceBox = wx.BoxSizer(wx.HORIZONTAL) sourceBox = wx.BoxSizer(wx.HORIZONTAL)
sourceBox.Add(sourceLabel, 0, wx.ALL, 5) sourceBox.Add(sourceLabel, 0, wx.ALL, 5)
sourceBox.Add(sourceTweet, 0, wx.ALL, 5) sourceBox.Add(sourceTweet, 0, wx.ALL, 5)
dateLabel = wx.StaticText(panel, -1, _(u"Date: "))
dateTweet = wx.TextCtrl(panel, -1, date, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
dc = wx.WindowDC(dateTweet)
dc.SetFont(dateTweet.GetFont())
(x, y) = dc.GetTextExtent("0"*100)
dateTweet.SetSize((x, y))
dateBox = wx.BoxSizer(wx.HORIZONTAL)
dateBox.Add(dateLabel, 0, wx.ALL, 5)
dateBox.Add(dateTweet, 0, wx.ALL, 5)
infoBox = wx.BoxSizer(wx.HORIZONTAL) infoBox = wx.BoxSizer(wx.HORIZONTAL)
infoBox.Add(rtBox, 0, wx.ALL, 5) infoBox.Add(rtBox, 0, wx.ALL, 5)
infoBox.Add(favsBox, 0, wx.ALL, 5) infoBox.Add(favsBox, 0, wx.ALL, 5)
infoBox.Add(sourceBox, 0, wx.ALL, 5) infoBox.Add(sourceBox, 0, wx.ALL, 5)
mainBox.Add(infoBox, 0, wx.ALL, 5) mainBox.Add(infoBox, 0, wx.ALL, 5)
mainBox.Add(dateBox, 0, wx.ALL, 5)
self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize) self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize) self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
self.unshortenButton.Disable() self.unshortenButton.Disable()
@ -390,7 +400,7 @@ class viewTweet(widgetUtils.BaseDialog):
class viewNonTweet(widgetUtils.BaseDialog): class viewNonTweet(widgetUtils.BaseDialog):
def __init__(self, text, *args, **kwargs): def __init__(self, text, date="", *args, **kwargs):
super(viewNonTweet, self).__init__(None, size=(850,850)) super(viewNonTweet, self).__init__(None, size=(850,850))
self.SetTitle(_(u"View")) self.SetTitle(_(u"View"))
panel = wx.Panel(self) panel = wx.Panel(self)
@ -406,6 +416,17 @@ class viewNonTweet(widgetUtils.BaseDialog):
textBox.Add(self.text, 1, wx.EXPAND, 5) textBox.Add(self.text, 1, wx.EXPAND, 5)
mainBox = wx.BoxSizer(wx.VERTICAL) mainBox = wx.BoxSizer(wx.VERTICAL)
mainBox.Add(textBox, 0, wx.ALL, 5) mainBox.Add(textBox, 0, wx.ALL, 5)
if date != "":
dateLabel = wx.StaticText(panel, -1, _(u"Date: "))
date = wx.TextCtrl(panel, -1, date, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
dc = wx.WindowDC(date)
dc.SetFont(date.GetFont())
(x, y) = dc.GetTextExtent("0"*100)
date.SetSize((x, y))
dateBox = wx.BoxSizer(wx.HORIZONTAL)
dateBox.Add(dateLabel, 0, wx.ALL, 5)
dateBox.Add(date, 0, wx.ALL, 5)
mainBox.Add(dateBox, 0, wx.ALL, 5)
self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize) self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize) self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
self.unshortenButton.Disable() self.unshortenButton.Disable()