Skip to content

Commit

Permalink
add share command and show Twitter client name
Browse files Browse the repository at this point in the history
  • Loading branch information
orakaro committed Sep 24, 2014
1 parent 47cee70 commit 413857b
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = '1.0.7'
version = '1.0.8'
# The full version, including alpha/beta/rc tags.
release = '1.0.7'
release = '1.0.8'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Expand Up @@ -144,6 +144,8 @@ Here is full list of supported command:

- ``ufav 12`` will unfavorite tweet with *[id=12]*.

- ``share 12`` will copy tweet with *[id=12]* to your clipboard.

- ``del 12`` will delete tweet with *[id=12]*.

- ``show image 12`` will show the image in tweet with *[id=12]* in your OS’s image viewer.
Expand Down
2 changes: 1 addition & 1 deletion rainbowstream/colorset/config
Expand Up @@ -53,7 +53,7 @@
"FORMAT": {
"TWEET": {
"CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S",
"DISPLAY" : "\n #name #nick #clock \n \u20AA:#rt_count \u2665:#fa_count id:#id #fav\n #tweet"
"DISPLAY" : "\n #name #nick #clock \n \u20AA:#rt_count \u2665:#fa_count id:#id via #client #fav\n #tweet"
},
"MESSAGE": {
"CLOCK_FORMAT" : "%Y/%m/%d %H:%M:%S",
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/larapaste.json
Expand Up @@ -27,6 +27,7 @@
"nick" : 37,
"clock" : 184,
"id" : 184,
"client" : 154,
"favorited" : 154,
"retweet_count" : 154,
"favorite_count" : 202,
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/monokai.json
Expand Up @@ -27,6 +27,7 @@
"nick" : 112,
"clock" : 57,
"id" : 166,
"client" : 74,
"favorited" : 50,
"retweet_count" : 50,
"favorite_count" : 198,
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/solarized.json
Expand Up @@ -27,6 +27,7 @@
"nick" : 64,
"clock" : 32,
"id" : 130,
"client" : 23,
"favorited" : 64,
"retweet_count" : 64,
"favorite_count" : 124,
Expand Down
1 change: 1 addition & 0 deletions rainbowstream/colorset/tomorrow_night.json
Expand Up @@ -27,6 +27,7 @@
"nick" : 67,
"clock" : 58,
"id" : 58,
"client" : 58,
"favorited" : 97,
"retweet_count" : 97,
"favorite_count" : 166,
Expand Down
12 changes: 12 additions & 0 deletions rainbowstream/draw.py
Expand Up @@ -190,6 +190,7 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
favorited = t['favorited']
retweet_count = t['retweet_count']
favorite_count = t['favorite_count']
client = t['source']
date = parser.parse(created_at)
try:
clock_format = c['FORMAT']['TWEET']['CLOCK_FORMAT']
Expand All @@ -215,6 +216,12 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
# Unescape HTML character
text = unescape(text)

# Get client name
try:
client = client.split('>')[-2].split('<')[0]
except:
client = None

# Get expanded url
try:
expanded_url = []
Expand Down Expand Up @@ -330,6 +337,11 @@ def draw(t, keyword=None, humanize=True, noti=False, fil=[], ig=[]):
word = [wo for wo in formater.split() if '#id' in wo][0]
delimiter = color_func(c['TWEET']['id'])(id.join(word.split('#id')))
formater = delimiter.join(formater.split(word))
# Change client word
word = [wo for wo in formater.split() if '#client' in wo][0]
delimiter = color_func(c['TWEET']['client'])(
client.join(word.split('#client')))
formater = delimiter.join(formater.split(word))
# Change retweet count word
word = [wo for wo in formater.split() if '#rt_count' in wo][0]
delimiter = color_func(c['TWEET']['retweet_count'])(
Expand Down
24 changes: 24 additions & 0 deletions rainbowstream/rainbow.py
Expand Up @@ -482,6 +482,24 @@ def unfavorite():
printNicely('')


def share():
"""
Copy url of a tweet to clipboard
"""
t = Twitter(auth=authen())
try:
id = int(g['stuff'].split()[0])
except:
printNicely(red('Sorry I can\'t understand.'))
return
tid = c['tweet_dict'][id]
tweet = t.statuses.show(id=tid)
url = 'https://twitter.com/' + \
tweet['user']['screen_name'] + '/status/' + str(tid)
os.system("echo '%s' | pbcopy" % url)
printNicely(green('Copied tweet\'s url to clipboard.'))


def delete():
"""
Delete
Expand Down Expand Up @@ -1394,6 +1412,9 @@ def help_tweets():
usage += s * 2 + \
light_green('ufav 12 ') + ' will unfavorite tweet with ' + \
light_yellow('[id=12]') + '.\n'
usage += s * 2 + \
light_green('share 12 ') + ' will copy the url of the tweet with ' + \
light_yellow('[id=12]') + ' to your clipboard.\n'
usage += s * 2 + \
light_green('del 12 ') + ' will delete tweet with ' + \
light_yellow('[id=12]') + '.\n'
Expand Down Expand Up @@ -1674,6 +1695,7 @@ def reset():
'rep',
'del',
'ufav',
'share',
's',
'mes',
'show',
Expand Down Expand Up @@ -1719,6 +1741,7 @@ def reset():
reply,
delete,
unfavorite,
share,
search,
message,
show,
Expand Down Expand Up @@ -1777,6 +1800,7 @@ def listen():
[], # reply
[], # delete
[], # unfavorite
[], # url
['#'], # search
['@'], # message
['image'], # show image
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
import os.path

# Bumped version
version = '1.0.7'
version = '1.0.8'

# Require
install_requires = [
Expand Down
6 changes: 5 additions & 1 deletion theme.md
Expand Up @@ -25,15 +25,18 @@ Examples are available in
"DECORATED_NAME" : 198,
"CYCLE_COLOR" :[198,57,166,50,179,74,112],
"TWEET" : {
"mynick" : 179,
"nick" : 112,
"clock" : 57,
"id" : 166,
"client" : 74,
"favorited" : 50,
"retweet_count" : 50,
"favorite_count" : 198,
"rt" : 179,
"link" : 74,
"hashtag" : 198,
"mytweet" : 179,
"keyword" : "on_light_green"
},

Expand All @@ -46,8 +49,8 @@ Examples are available in
"MESSAGE" : {
"partner" : 112,
"me" : 112,
"me_frame" : 74,
"partner_frame" : 198,
"me_frame" : 74,
"sender" : 112,
"recipient" : 112,
"to" : 50,
Expand Down Expand Up @@ -144,6 +147,7 @@ Color reference can be found at
* `nick` : color for other Twitter __username__.
* `clock`: color for time of tweet.
* `id`: color for tweet's id.
* `client`: color for used Twitter client.
* `favorite`: color for the star symbol when a tweet is favorited by you.
* `retweet_count`: color for retweets count.
* `favorite_count`: color for favorites count.
Expand Down

0 comments on commit 413857b

Please sign in to comment.