From 13bcdaf1ab4c477633a164e7a4e8453e3c13a7f8 Mon Sep 17 00:00:00 2001 From: Lertsenem Date: Sun, 9 Oct 2016 02:34:06 +0200 Subject: [PATCH] Make use of modern-style quotes (See issue https://github.com/DTVD/rainbowstream/issues/134) Twitter introduced a new way of quoting, by simply putting the tweet url as a quote. The web interface (and most clients) will then display a preview of the quoted tweet, leaving more characters available for your quote. This patch change the default quote format from the old mode ("#comment RT #owner #text") to the new one, introducing a new #tid keyword holding the tweet id (needed to find the tweet URL). It's still possible to go back to the old mode, by changing the QUOTE_FORMAT config parameter back to "#comment RT @#owner #text". --- docs/index.rst | 3 ++- rainbowstream/colorset/config | 2 +- rainbowstream/draw.py | 14 ++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 44cc068..0fa1319 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -351,8 +351,9 @@ You also can view or set a new value of every config key by ``config`` command ( - ``QUOTE_FORMAT``: format when quote a tweet + ``#comment``: Your own comment about the tweet - + ``#owner``: owner's username with '@' + + ``#owner``: owner's username *without* '@' + ``#tweet``: original tweet + + ``#tid``: the tweet id on Twitter - ``THREAD_META_LEFT``: format for meta information of messages from partner which is display in the left of screen. diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config index a9ee3fd..6bfd43e 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -24,7 +24,7 @@ // 'conversation': max tweet in a thread "CONVERSATION_MAX" : 30, // 'quote' format - "QUOTE_FORMAT" : "#comment RT #owner: #tweet", + "QUOTE_FORMAT" : "#comment https:\/\/twitter.com\/#owner\/status\/#tid", // 'thread' meta format "THREAD_META_LEFT" : "(#id) #clock", "THREAD_META_RIGHT" : "#clock (#id)", diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index ab20276..4423c26 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -1066,8 +1066,10 @@ def format_quote(tweet): Quoting format """ # Retrieve info - screen_name = '@' + tweet['user']['screen_name'] - text = tweet['text'] + screen_name = str( tweet['user']['screen_name'] ) + text = str( tweet['text'] ) + tid = str( tweet['id'] ) + # Validate quote format if '#owner' not in c['QUOTE_FORMAT']: printNicely(light_magenta('Quote should contains #owner')) @@ -1075,12 +1077,16 @@ def format_quote(tweet): if '#comment' not in c['QUOTE_FORMAT']: printNicely(light_magenta('Quote format should have #comment')) return False + # Build formater formater = '' try: formater = c['QUOTE_FORMAT'] - formater = screen_name.join(formater.split('#owner')) - formater = text.join(formater.split('#tweet')) + + formater = formater.replace('#owner', screen_name) + formater = formater.replace('#tweet', text) + formater = formater.replace('#tid', tid) + formater = emojize(formater) except: pass -- 2.25.1