Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render quoted tweet like twitter.com #214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rainbowstream/colorset/config
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"FORMAT": {
"TWEET": {
"CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S",
"DISPLAY" : "\n #name #nick #clock \n \u267A:#rt_count \u2665:#fa_count id:#id via #client #fav\n #tweet"
"DISPLAY" : "\n #name #nick #clock \n \u267A:#rt_count \u2665:#fa_count id:#id via #client #fav\n #tweet #quoted_status"
},
"MESSAGE": {
"CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S",
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/larapaste.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"favorited" : 154,
"retweet_count" : 154,
"favorite_count" : 202,
"quoted_status" : "red",
"rt" : 202,
"link" : 154,
"hashtag" : 37,
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/monokai.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"favorited" : 50,
"retweet_count" : 50,
"favorite_count" : 198,
"quoted_status" : "red",
"rt" : 179,
"link" : 74,
"hashtag" : 198,
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/solarized.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"favorited" : 64,
"retweet_count" : 64,
"favorite_count" : 124,
"quoted_status" : "red",
"rt" : 66,
"link" : 23,
"hashtag" : 64,
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/tomorrow_night.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"favorited" : 97,
"retweet_count" : 97,
"favorite_count" : 166,
"quoted_status" : "red",
"rt" : 145,
"link" : 30,
"hashtag" : 67,
Expand Down
31 changes: 23 additions & 8 deletions rainbowstream/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
# Retrieve tweet
tid = t['id']
text = t['text']
quoted_status = ''
screen_name = t['user']['screen_name']
name = t['user']['name']
created_at = t['created_at']
Expand Down Expand Up @@ -214,9 +215,17 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
except:
pass

# Pull quoted status
try:
quoted_status = ' ++++++++++++ \n' +\
' ' + t['quoted_status']['user']['name'] + ' @' + t['quoted_status']['user']['screen_name'] + '\n ' +\
' ' + t['quoted_status']['text'] + '\n +++++++++++ \n'
quoted_status = unescape(quoted_status)
except:
pass

# Unescape HTML character
text = unescape(text)

# Get client name
try:
client = client.split('>')[-2].split('<')[0]
Expand Down Expand Up @@ -332,6 +341,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
formater = nick.join(formater.split('#nick'))
formater = fav.join(formater.split('#fav'))
formater = tweet.join(formater.split('#tweet'))
formater = color_func(c['TWEET']['quoted_status'])(quoted_status).join(formater.split('#quoted_status'))
formater = emojize(formater)
# Change clock word
word = [wo for wo in formater.split() if '#clock' in wo][0]
Expand Down Expand Up @@ -370,14 +380,19 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
# Draw
printNicely(formater)


# Display Image
if c['IMAGE_ON_TERM'] and media_url:
for mu in media_url:
try:
response = requests.get(mu)
image_to_display(BytesIO(response.content))
except Exception:
printNicely(red('Sorry, image link is broken'))
if media_url:
if c['IMAGE_ON_TERM']:
for mu in media_url:
try:
response = requests.get(mu)
image_to_display(BytesIO(response.content))
except Exception as e:
print e
printNicely(red('Sorry, image link is broken'))
else:
printNicely(red(' Image available'))


def print_threads(d):
Expand Down