-## Rainbow Stream
+## Rainbow Stream
[![Download](http://img.shields.io/pypi/dm/rainbowstream.svg?style=flat)](https://pypi.python.org/pypi/rainbowstream)
[![Version](http://img.shields.io/pypi/v/rainbowstream.svg?style=flat)](https://pypi.python.org/pypi/rainbowstream)
-Terminal-based Twitter Client.
+Terminal-based Twitter Client.
Realtime tweetstream, compose, search , favorite ... and much more fun directly from terminal.
This package build on the top of [Python Twitter Tool](http://mike.verdone.ca/twitter/) and [Twitter API](https://dev.twitter.com/docs/api/1.1).
__Action Commands__
-* ```trend```will show global trending topics. ```trend US``` will show trends in United States while ```trend JP Tokyo``` will show trends in Tokyo/Japan.
+* `trend` will show global trending topics. `trend US` will show trends in United States while `trend JP Tokyo` will show trends in Tokyo/Japan.
-* ```home```will show your timeline. ```home 10``` will print exactly 10 tweets.
+* `home` will show your timeline. `home 10` will print exactly 10 tweets.
-* ```view @mdo```will show @mdo 's timeline. ```view @dmo 9``` will print exactly 9 tweets.
+* `view @mdo` will show @mdo 's timeline. `view @dmo 9` will print exactly 9 tweets.
-* ```mentions```will show mentions timeline. ```mentions 7``` will show 7 mention tweets.
+* `mentions` will show mentions timeline. `mentions 7` will show 7 mention tweets.
-* ```t the rainbow is god's promise to noah```will tweet exactly *'the rainbow is god's promise to noah'*.
+* `t the rainbow is god's promise to noah` will tweet exactly *'the rainbow is god's promise to noah'*.
-* ```rt 12```will retweet the tweet with *[id=12]*. You can see id of each tweet beside the time.
+* `rt 12` will retweet the tweet with *[id=12]*. You can see id of each tweet beside the time.
-* ```fav 12```will favorite the tweet with *[id=12]*.
+* `fav 12` will favorite the tweet with *[id=12]*.
-* ```rep 12 Really```will reply *'Really'* to the tweet with *[id=12]*.
+* `rep 12 Really` will reply *'Really'* to the tweet with *[id=12]*.
-* ```del 12```will delete tweet with *[id=12]*.
+* `del 12` will delete tweet with *[id=12]*.
-* ```ufav 12```will unfavorite tweet with *[id=12]*.
+* `ufav 12` will unfavorite tweet with *[id=12]*.
-* ```s #noah```will search the word *'noah'*. Result will come back with highlight.
+* `s #noah` will search the word *'noah'*. Result will come back with highlight.
-* ```mes @dtvd88 hi```will send a ```hi``` message to @dtvd88.
+* `mes @dtvd88 hi` will send a `hi` message to @dtvd88.
-* ```show image 12``` will show the image in tweet with *[id=12]* in your OS's image viewer.
+* `show image 12` will show the image in tweet with *[id=12]* in your OS's image viewer.
-* ```ls fl```will list all your followers (people who are following you).
+* `ls fl` will list all your followers (people who are following you).
-* ```ls fr```will list all your friends (people who you are following).
+* `ls fr` will list all your friends (people who you are following).
-* ```inbox```will show inbox messages. ```inbox 7``` will show newest 7 messages.
+* `inbox` will show inbox messages. `inbox 7` will show newest 7 messages.
-* ```sent```will show sent messages. ```sent 7``` will show newest 7 messages.
+* `sent` will show sent messages. `sent 7` will show newest 7 messages.
-* ```trash 5```will remove message with *[message_id=5]*
+* `trash 5` will remove message with *[message_id=5]*
-* ```whois @dtvd88```will show profile of @dtvd88.
+* `whois @dtvd88` will show profile of @dtvd88.
-* ```fl @dtvd88```will follow @dtvd88.
+* `fl @dtvd88` will follow @dtvd88.
-* ```ufl @dtvd88```will unfollow @dtvd88.
+* `ufl @dtvd88` will unfollow @dtvd88.
-* ```h```will show the help.
+* `h` will show the help.
-* ```c```will clear the screen.
+* `c` will clear the screen.
-* ```q```will quit.
+* `q` will quit.
__Stream Commands__
-* ```switch public #AKB48``` will switch current stream to public stream and track keyword ```AKB48```
+* `switch public #AKB48` will switch current stream to public stream and track keyword `AKB48`
-* ```switch public #AKB48 -f ``` will do exactly as above but will ask you to provide 2 list:
+* `switch public #AKB48 -f ` will do exactly as above but will ask you to provide 2 list:
- ```Only nicks``` decide what nicks will be include only.
+ `Only nicks` decide what nicks will be include only.
- ```Ignore nicks```decide what nicks will be exclude.
+ `Ignore nicks`decide what nicks will be exclude.
-* ```switch public #AKB48 -d ``` will apply filter to *ONLY_LIST* and *IGNORE_LIST*.
-You can setup 2 list above at ```config.py```
+* `switch public #AKB48 -d ` will apply filter to *ONLY_LIST* and *IGNORE_LIST*.
+You can setup 2 list above at `config.py`
-* ```switch mine``` will switch current stream to personal stream. ```-f``` and ```-d``` will work as well.
+* `switch mine` will switch current stream to personal stream. `-f` and `-d` will work as well.
For example see the screenshot above.
## Bug Report
-Please [create an issue](https://github.com/DTVD/rainbowstream/issues/new)
+Please [create an issue](https://github.com/DTVD/rainbowstream/issues/new)
or contact me at [@dtvd88](https://twitter.com/dtvd88)
## License
Rainbow Stream\r
--------------\r
\r
-.. image:: http://img.shields.io/pypi/dm/rainbowstream.svg?style=flat\r
- :target: https://pypi.python.org/pypi/rainbowstream\r
-\r
-.. image:: http://img.shields.io/pypi/v/rainbowstream.svg?style=flat\r
- :target: https://pypi.python.org/pypi/rainbowstream\r
+|Download| |Version|\r
\r
Terminal-based Twitter Client. Realtime tweetstream, compose, search ,\r
favorite … and much more fun directly from terminal.\r
\r
-This package build on the top of `Python Twitter Tool`_ and `Twitter API`_.\r
+This package build on the top of `Python Twitter Tool`_ and `Twitter\r
+API`_.\r
\r
Screenshot\r
----------\r
\r
-.. figure:: https://raw.githubusercontent.com/DTVD/rainbowstream/master/screenshot/RainbowStream.png\r
- :alt: rainbowstream\r
-\r
-.. figure:: https://raw.githubusercontent.com/DTVD/rainbowstream/master/screenshot/RainbowStreamIOT.png\r
- :alt: rainbowstreamIOT\r
+|rainbowstream| |rainbowstreamIOT|\r
\r
Install\r
-------\r
\r
and see your stream.\r
\r
-I shipped a feature which can display **tweet's images directly on terminal**.\r
-You can try it with:\r
+I shipped a feature which can display **tweet’s images directly on\r
+terminal**. You can try it with:\r
\r
.. code:: bash\r
\r
\r
In the first time you will be asked for authorization of Rainbow Stream\r
app at Twitter. Just click the “Authorize access” button and paste PIN\r
-number to the terminal, the rainbow will start.\r
+number to the terminal, the rainbow will start\r
+\r
\r
The interactive mode\r
^^^^^^^^^^^^^^^^^^^^\r
**Action Commands**\r
\r
- ``trend`` will show global trending topics. ``trend US`` will show\r
- trends in United States while ``trend JP Tokyo`` will show trends\r
- in Tokyo/Japan.\r
+ trends in United States while ``trend JP Tokyo`` will show trends in\r
+ Tokyo/Japan.\r
\r
- ``home`` will show your timeline. ``home 10`` will print exactly 10\r
tweets.\r
- ``view @mdo`` will show @mdo ’s timeline. ``view @dmo 9`` will print\r
exactly 9 tweets.\r
\r
-- ``mentions`` will show mentions timeline. ``mentions 7`` will show\r
- 7 mention tweets.\r
+- ``mentions`` will show mentions timeline. ``mentions 7`` will show 7\r
+ mention tweets.\r
\r
- ``t the rainbow is god's promise to noah`` will tweet exactly *‘the\r
- rainbow is god’s promise to noah’*\r
+ rainbow is god’s promise to noah’*.\r
\r
- ``rt 12`` will retweet the tweet with *[id=12]*. You can see id of\r
each tweet beside the time.\r
\r
- ``ufav 12`` will unfavorite tweet with *[id=12]*.\r
\r
-- ``s #noah`` will search the word *‘noah’*. Result will come back\r
- with highlight.\r
+- ``s #noah`` will search the word *‘noah’*. Result will come back with\r
+ highlight.\r
\r
- ``mes @dtvd88 hi`` will send a ``hi`` message to @dtvd88.\r
\r
-- ``show image 12`` will show the image in tweet with *[id=12]* in your OS's image viewer.\r
+- ``show image 12`` will show the image in tweet with *[id=12]* in your\r
+ OS’s image viewer.\r
\r
-- ``ls fl`` will list all your followers (people who are following you).\r
+- ``ls fl`` will list all your followers (people who are following\r
+ you).\r
\r
- ``ls fr`` will list all your friends (people who you are following).\r
\r
-- ``inbox`` will show inbox messages. ``inbox 7`` will show newest\r
- 7 message.\r
+- ``inbox`` will show inbox messages. ``inbox 7`` will show newest 7\r
+ messages.\r
\r
-- ``sent`` will show sent messages. ``sent 7`` will show newest\r
- 7 message.\r
+- ``sent`` will show sent messages. ``sent 7`` will show newest 7\r
+ messages.\r
\r
-- ``trash 5`` will remove message with *[message_id=5]*.\r
+- ``trash 5`` will remove message with *[message\_id=5]*\r
\r
- ``whois @dtvd88`` will show profile of @dtvd88.\r
\r
\r
**Stream Commands**\r
\r
-- ``switch public #AKB48`` will switch current stream to public stream and track keyword ``AKB48``\r
+- ``switch public #AKB48`` will switch current stream to public stream\r
+ and track keyword ``AKB48``\r
\r
- ``switch public #AKB48 -f`` will do exactly as above but will ask you\r
to provide 2 list:\r
\r
``Only nicks`` decide what nicks will be include only.\r
\r
- ``Ignore nicks`` decide what nicks will be exclude.\r
+ ``Ignore nicks``\ decide what nicks will be exclude.\r
\r
- ``switch public #AKB48 -d`` will apply filter to *ONLY\_LIST* and\r
*IGNORE\_LIST*. You can setup 2 list above at ``config.py``\r
- ``switch mine`` will switch current stream to personal stream. ``-f``\r
and ``-d`` will work as well.\r
\r
-\r
For example see the screenshot above.\r
\r
Bug Report\r
----------\r
\r
-Please `create an issue`_ or contact me at `@dtvd88`_\r
+Please `create an issue`_ or contact me at\r
+[@dtvd88](https://twitter.com/dtvd88)\r
\r
License\r
-------\r
\r
.. _Python Twitter Tool: http://mike.verdone.ca/twitter/\r
.. _Twitter API: https://dev.twitter.com/docs/api/1.1\r
-.. _EarthQuake: https://github.com/jugyo/earthquake\r
.. _create an issue: https://github.com/DTVD/rainbowstream/issues/new\r
-.. _@dtvd88: https://twitter.com/dtvd88\r
+\r
+.. |Download| image:: http://img.shields.io/pypi/dm/rainbowstream.svg?style=flat\r
+ :target: https://pypi.python.org/pypi/rainbowstream\r
+.. |Version| image:: http://img.shields.io/pypi/v/rainbowstream.svg?style=flat\r
+ :target: https://pypi.python.org/pypi/rainbowstream\r
+.. |rainbowstream| image:: ./screenshot/RainbowStream.png\r
+.. |rainbowstreamIOT| image:: ./screenshot/RainbowStreamIOT.png
\ No newline at end of file
t = Twitter(auth=authen())
try:
id = int(g['stuff'].split()[0])
- tid = db.rainbow_to_tweet_query(id)[0].tweet_id
- t.statuses.retweet(id=tid, include_entities=False, trim_user=True)
except:
- printNicely(red('Sorry I can\'t retweet for you.'))
+ printNicely(red('Sorry I can\'t understand.'))
+ return
+ tid = db.rainbow_to_tweet_query(id)[0].tweet_id
+ t.statuses.retweet(id=tid, include_entities=False, trim_user=True)
def favorite():
t = Twitter(auth=authen())
try:
id = int(g['stuff'].split()[0])
- tid = db.rainbow_to_tweet_query(id)[0].tweet_id
- t.favorites.create(_id=tid, include_entities=False)
- printNicely(green('Favorited.'))
- draw(t.statuses.show(id=tid), iot=g['iot'])
- printNicely('')
except:
- printNicely(red('Omg some syntax is wrong.'))
+ printNicely(red('Sorry I can\'t understand.'))
+ return
+ tid = db.rainbow_to_tweet_query(id)[0].tweet_id
+ t.favorites.create(_id=tid, include_entities=False)
+ printNicely(green('Favorited.'))
+ draw(t.statuses.show(id=tid), iot=g['iot'])
+ printNicely('')
def reply():
t = Twitter(auth=authen())
try:
id = int(g['stuff'].split()[0])
- tid = db.rainbow_to_tweet_query(id)[0].tweet_id
- user = t.statuses.show(id=tid)['user']['screen_name']
- status = ' '.join(g['stuff'].split()[1:])
- status = '@' + user + ' ' + status.decode('utf-8')
- t.statuses.update(status=status, in_reply_to_status_id=tid)
except:
printNicely(red('Sorry I can\'t understand.'))
+ return
+ tid = db.rainbow_to_tweet_query(id)[0].tweet_id
+ user = t.statuses.show(id=tid)['user']['screen_name']
+ status = ' '.join(g['stuff'].split()[1:])
+ status = '@' + user + ' ' + status.decode('utf-8')
+ t.statuses.update(status=status, in_reply_to_status_id=tid)
def delete():
t = Twitter(auth=authen())
try:
rid = int(g['stuff'].split()[0])
- tid = db.rainbow_to_tweet_query(rid)[0].tweet_id
- t.statuses.destroy(id=tid)
- printNicely(green('Okay it\'s gone.'))
except:
printNicely(red('Sorry I can\'t understand.'))
+ return
+ tid = db.rainbow_to_tweet_query(rid)[0].tweet_id
+ t.statuses.destroy(id=tid)
+ printNicely(green('Okay it\'s gone.'))
def unfavorite():
t = Twitter(auth=authen())
try:
id = int(g['stuff'].split()[0])
- tid = db.rainbow_to_tweet_query(id)[0].tweet_id
- t.favorites.destroy(_id=tid)
- printNicely(green('Okay it\'s unfavorited.'))
- draw(t.statuses.show(id=tid), iot=g['iot'])
- printNicely('')
except:
- printNicely(red('Sorry I can\'t unfavorite this tweet for you.'))
+ printNicely(red('Sorry I can\'t understand.'))
+ return
+ tid = db.rainbow_to_tweet_query(id)[0].tweet_id
+ t.favorites.destroy(_id=tid)
+ printNicely(green('Okay it\'s unfavorited.'))
+ draw(t.statuses.show(id=tid), iot=g['iot'])
+ printNicely('')
def search():
Search
"""
t = Twitter(auth=authen())
- try:
- if g['stuff'][0] == '#':
- rel = t.search.tweets(q=g['stuff'])['statuses']
- if len(rel):
- printNicely('Newest tweets:')
- for i in reversed(xrange(SEARCH_MAX_RECORD)):
- draw(t=rel[i],
- iot=g['iot'],
- keyword=g['stuff'].strip()[1:])
- printNicely('')
- else:
- printNicely(magenta('I\'m afraid there is no result'))
+ if g['stuff'].startswith('#'):
+ rel = t.search.tweets(q=g['stuff'])['statuses']
+ if len(rel):
+ printNicely('Newest tweets:')
+ for i in reversed(xrange(SEARCH_MAX_RECORD)):
+ draw(t=rel[i],
+ iot=g['iot'],
+ keyword=g['stuff'].strip()[1:])
+ printNicely('')
else:
- printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
- except:
- printNicely(red('Sorry I can\'t understand.'))
+ printNicely(magenta('I\'m afraid there is no result'))
+ else:
+ printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
def message():
"""
t = Twitter(auth=authen())
user = g['stuff'].split()[0]
- if user[0] == '@':
+ if user[0].startswith('@'):
try:
content = g['stuff'].split()[1]
- t.direct_messages.new(
- screen_name=user[1:],
- text=content
- )
- printNicely(green('Message sent.'))
except:
printNicely(red('Sorry I can\'t understand.'))
+ t.direct_messages.new(
+ screen_name=user[1:],
+ text=content
+ )
+ printNicely(green('Message sent.'))
else:
printNicely(red('A name should begin with a \'@\''))
# Get name
try:
name = g['stuff'].split()[1]
- if name[0] == '@':
+ if name.startswith('@'):
name = name[1:]
else:
printNicely(red('A name should begin with a \'@\''))
# Get list followers or friends
try:
target = g['stuff'].split()[0]
- d = {'fl': 'followers', 'fr': 'friends'}
- next_cursor = -1
- rel = {}
- # Cursor loop
- while next_cursor != 0:
- list = getattr(t, d[target]).list(
- screen_name=name,
- cursor=next_cursor,
- skip_status=True,
- include_entities=False,
- )
- for u in list['users']:
- rel[u['name']] = '@' + u['screen_name']
- next_cursor = list['next_cursor']
- # Print out result
- printNicely('All: ' + str(len(rel)) + ' people.')
- for name in rel:
- user = ' ' + cycle_color(name) + grey(' ' + rel[name] + ' ')
- printNicely(user)
except:
printNicely(red('Omg some syntax is wrong.'))
+ # Init cursor
+ d = {'fl': 'followers', 'fr': 'friends'}
+ next_cursor = -1
+ rel = {}
+ # Cursor loop
+ while next_cursor != 0:
+ list = getattr(t, d[target]).list(
+ screen_name=name,
+ cursor=next_cursor,
+ skip_status=True,
+ include_entities=False,
+ )
+ for u in list['users']:
+ rel[u['name']] = '@' + u['screen_name']
+ next_cursor = list['next_cursor']
+ # Print out result
+ printNicely('All: ' + str(len(rel)) + ' people.')
+ for name in rel:
+ user = ' ' + cycle_color(name) + grey(' ' + rel[name] + ' ')
+ printNicely(user)
def inbox():
t = Twitter(auth=authen())
try:
rid = int(g['stuff'].split()[0])
- mid = db.rainbow_to_message_query(rid)[0].message_id
- t.direct_messages.destroy(id=mid)
- printNicely(green('Message deleted.'))
except:
printNicely(red('Sorry I can\'t understand.'))
+ mid = db.rainbow_to_message_query(rid)[0].message_id
+ t.direct_messages.destroy(id=mid)
+ printNicely(green('Message deleted.'))
def whois():
"""
t = Twitter(auth=authen())
screen_name = g['stuff'].split()[0]
- if screen_name[0] == '@':
+ if screen_name.startswith('@'):
try:
user = t.users.show(
screen_name=screen_name[1:],
except:
printNicely(red('Omg no user.'))
else:
- printNicely(red('Sorry I can\'t understand.'))
+ printNicely(red('A name should begin with a \'@\''))
def follow():
"""
t = Twitter(auth=authen())
screen_name = g['stuff'].split()[0]
- if screen_name[0] == '@':
- try:
- t.friendships.create(screen_name=screen_name[1:], follow=True)
- printNicely(green('You are following ' + screen_name + ' now!'))
- except:
- printNicely(red('Sorry can not follow at this time.'))
+ if screen_name.startswith('@'):
+ t.friendships.create(screen_name=screen_name[1:], follow=True)
+ printNicely(green('You are following ' + screen_name + ' now!'))
else:
- printNicely(red('Sorry I can\'t understand.'))
+ printNicely(red('A name should begin with a \'@\''))
def unfollow():
"""
t = Twitter(auth=authen())
screen_name = g['stuff'].split()[0]
- if screen_name[0] == '@':
- try:
- t.friendships.destroy(
- screen_name=screen_name[1:],
- include_entities=False)
- printNicely(green('Unfollow ' + screen_name + ' success!'))
- except:
- printNicely(red('Sorry can not unfollow at this time.'))
+ if screen_name.startswith('@'):
+ t.friendships.destroy(
+ screen_name=screen_name[1:],
+ include_entities=False)
+ printNicely(green('Unfollow ' + screen_name + ' success!'))
else:
- printNicely(red('Sorry I can\'t understand.'))
+ printNicely(red('A name should begin with a \'@\''))
def block():
"""
t = Twitter(auth=authen())
screen_name = g['stuff'].split()[0]
- if screen_name[0] == '@':
- try:
- t.blocks.create(
- screen_name=screen_name[1:],
- include_entities=False,
- skip_status=True)
- printNicely(green('You blocked ' + screen_name + '.'))
- except:
- printNicely(red('Sorry something went wrong.'))
+ if screen_name.startswith('@'):
+ t.blocks.create(
+ screen_name=screen_name[1:],
+ include_entities=False,
+ skip_status=True)
+ printNicely(green('You blocked ' + screen_name + '.'))
else:
- printNicely(red('Sorry I can\'t understand.'))
+ printNicely(red('A name should begin with a \'@\''))
def unblock():
"""
t = Twitter(auth=authen())
screen_name = g['stuff'].split()[0]
- if screen_name[0] == '@':
- try:
- t.blocks.destroy(
- screen_name=screen_name[1:],
- include_entities=False,
- skip_status=True)
- printNicely(green('Unblock ' + screen_name + ' success!'))
- except:
- printNicely(red('Sorry something went wrong.'))
+ if screen_name.startswith('@'):
+ t.blocks.destroy(
+ screen_name=screen_name[1:],
+ include_entities=False,
+ skip_status=True)
+ printNicely(green('Unblock ' + screen_name + ' success!'))
else:
- printNicely(red('Sorry I can\'t understand.'))
+ printNicely(red('A name should begin with a \'@\''))
def report():
"""
t = Twitter(auth=authen())
screen_name = g['stuff'].split()[0]
- if screen_name[0] == '@':
- try:
- t.users.report_spam(
- screen_name=screen_name[1:])
- printNicely(green('You reported ' + screen_name + '.'))
- except:
- printNicely(red('Sorry something went wrong.'))
+ if screen_name.startswith('@'):
+ t.users.report_spam(
+ screen_name=screen_name[1:])
+ printNicely(green('You reported ' + screen_name + '.'))
else:
printNicely(red('Sorry I can\'t understand.'))
except:
cmd = ''
# Save cmd to global variable and call process
- g['stuff'] = ' '.join(line.split()[1:])
- process(cmd)()
+ try:
+ g['stuff'] = ' '.join(line.split()[1:])
+ process(cmd)()
+ except Exception:
+ printNicely(red('OMG something is wrong with Twitter right now.'))
+ # Not redisplay prefix
if cmd in ['switch', 't', 'rt', 'rep']:
g['prefix'] = False
else: