#### The interactive mode
While your personal stream is continued, you are also ready to tweet, search, reply, retweet... directly from console.
-Simply type "h" and hit the Enter key to see the help
+Simply type "h" and hit the Enter key to see the help.
-Input is in interactive mode. It means that you can use arrow key to move up and down history, tab-autocomplete or 2 tab to view available suggestion
+Input is in interactive mode. It means that you can use arrow key to move up and down history, tab-autocomplete or 2 tab to view available suggestion. Input history from previous run is available as well.
Here is full list of supported command
* ```s #noah```will search the word *'noah'*. Result will come back with highlight.
-* ```fr```will list all friend (You are following people).
+* ```show image 12``` will show the image in tweet with *[id=12]* in your OS's image viewer.
-* ```fl```will list all follower.
+* ```fl @dtvd88```will follow @dtvd88.
+
+* ```ufl @dtvd88```will unfollow @dtvd88.
* ```h```will show the help.
\r
and see your stream.\r
\r
-In the case you want to see photos directly in terminal, the command is \r
+In the case you want to see photos directly in terminal, the command is\r
\r
.. code:: bash\r
\r
\r
While your personal stream is continued, you are also ready to tweet,\r
search, reply, retweet… directly from console. Simply type “h” and hit\r
-the Enter key to see the help\r
+the Enter key to see the help.\r
\r
Input is in interactive mode. It means that you can use arrow key to\r
move up and down history, tab-autocomplete or 2 tab to view available\r
-suggestion\r
+suggestion. Input history from previous run is available as well.\r
\r
Here is full list of supported command\r
\r
- ``s #noah`` will search the word *‘noah’*. Result will come back\r
with highlight.\r
\r
-- ``fr`` will list all friend (You are following people).\r
+- ``show image 12`` will show the image in tweet with *[id=12]* in your OS's image viewer.\r
\r
-- ``fl`` will list all follower.\r
+- ``fl @dtvd88`` will follow @dtvd88.\r
+\r
+- ``ufl @dtvd88`` will unfollow @dtvd88.\r
\r
- ``h`` will show the help.\r
\r
from PIL import Image
-from functools import partial
from os.path import join, dirname, getmtime, exists, expanduser
from .config import *
width = min(w, int(columns) - 2 * IMAGE_SHIFT)
height = int(float(h) * (float(width) / float(w)))
height //= 2
- i = i.resize((width, height), Image.BICUBIC)
+ i = i.resize((width, height), Image.ANTIALIAS)
height = min(height, IMAGE_MAX_HEIGHT)
for y in xrange(height):
SEARCH_MAX_RECORD = 5
# Default home tweet
HOME_TWEET_NUM = 5
+# Autocomplete history
+HISTORY_FILENAME = 'completer.hist'
# Stream Domain
USER_DOMAIN = 'userstream.twitter.com'
ONLY_LIST = []
IGNORE_LIST = []
-# Image size
+# Image shift and size
IMAGE_SHIFT = 10
-IMAGE_MAX_HEIGHT = 30
\ No newline at end of file
+IMAGE_MAX_HEIGHT = 300
\ No newline at end of file
+/*
+ * This source is borrowed from folowwing link
+ * https://github.com/jart/fabulous/blob/master/fabulous/_xterm256.c
+ * I make a slightly change to fit my module here
+ */
typedef struct {
int r;
int g;
import readline
import rlcompleter
+import os.path
+
+from .config import *
+
class RainbowCompleter(object):
return response
+def get_history_items():
+ """
+ Get all history item
+ """
+ return [
+ readline.get_history_item(i)
+ for i in xrange(1, readline.get_current_history_length() + 1)
+ ]
+
+
+def read_history():
+ """
+ Read history file
+ """
+ if os.path.isfile(HISTORY_FILENAME):
+ readline.read_history_file(HISTORY_FILENAME)
+
+
+def save_history():
+ """
+ Save history to file
+ """
+ readline.write_history_file(HISTORY_FILENAME)
+
+
def init_interactive_shell(d):
"""
Init the rainbow shell
import sys
import os
+"""
+This file is borrowed from following gist:
+https://gist.github.com/MicahElliott/719710
+It's too slow in compare with C program, so bot be used here
+"""
+
CLUT = [ # color look-up table
# 8-bit, RGB hex
'del',
'ufav',
's',
- 'fr',
+ 'show',
'fl',
+ 'ufl',
'h',
'c',
'q'
media_url = []
media = t['entities']['media']
for m in media:
- media_url = m['media_url']
+ media_url.append(m['media_url'])
except:
media_url = None
# Display Image
if imgflg and media_url:
- response = requests.get(media_url)
- image_to_display(StringIO(response.content))
+ for mu in media_url:
+ response = requests.get(mu)
+ image_to_display(StringIO(response.content))
def parse_arguments():
printNicely(red('Sorry I can\'t understand.'))
-def friend():
+def show():
"""
- List of friend (following)
+ Show image
"""
t = Twitter(auth=authen())
- g['friends'] = t.friends.ids()['ids']
- for i in g['friends']:
- name = t.users.lookup(user_id=i)[0]['name']
- screen_name = '@' + t.users.lookup(user_id=i)[0]['screen_name']
- user = cycle_color(name) + grey(' ' + screen_name + ' ')
- print user
+ try:
+ target = g['stuff'].split()[0]
+ if target != 'image':
+ return
+ id = int(g['stuff'].split()[1])
+ tid = db.rainbow_query(id)[0].tweet_id
+ tweet = t.statuses.show(id=tid)
+ media = tweet['entities']['media']
+ for m in media:
+ res = requests.get(m['media_url'])
+ img = Image.open(StringIO(res.content))
+ img.show()
+ except:
+ printNicely(red('Sorry I can\'t show this image.'))
-def follower():
+def follow():
"""
- List of follower
+ Follow a user
"""
t = Twitter(auth=authen())
- g['followers'] = t.followers.ids()['ids']
- for i in g['followers']:
- name = t.users.lookup(user_id=i)[0]['name']
- screen_name = '@' + t.users.lookup(user_id=i)[0]['screen_name']
- user = cycle_color(name) + grey(' ' + screen_name + ' ')
- print user
+ 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.'))
+ else:
+ printNicely(red('Sorry I can\'t understand.'))
+
+
+def unfollow():
+ """
+ Unfollow a user
+ """
+ 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.'))
+ else:
+ printNicely(red('Sorry I can\'t understand.'))
def help():
yellow('[id=12]') + '.\n'
usage += s * 2 + green('s #AKB48') + ' will search for "' + \
yellow('AKB48') + '" and return 5 newest tweet.\n'
- usage += s * 2 + green('fr') + ' will list out your following people.\n'
- usage += s * 2 + green('fl') + ' will list out your follower.\n'
+ usage += s * 2 + green('show image 12') + ' will show image in ' + \
+ yellow('[id=12]') + 'in your OS\'s image viewer.\n'
+ usage += s * 2 + green('fl @dtvd88') + ' will follow ' + \
+ yellow('@dtvd88') + '.\n'
+ usage += s * 2 + green('ufl @dtvd88') + ' will unfollow ' + \
+ yellow('@dtvd88') + '.\n'
usage += s * 2 + green('h') + ' will show this help again.\n'
usage += s * 2 + green('c') + ' will clear the screen.\n'
usage += s * 2 + green('q') + ' will quit.\n'
"""
Exit all
"""
+ save_history()
os.system('rm -rf rainbow.db')
os.kill(g['stream_pid'], signal.SIGKILL)
sys.exit()
delete,
unfavorite,
search,
- friend,
- follower,
+ show,
+ follow,
+ unfollow,
help,
clear,
quit
['@'], # view
[], # tweet
[], # retweet
+ [], # favorite
[], # reply
[], # delete
+ [], # unfavorite
['#'], # search
- [], # friend
- [], # follower
+ ['image'], # show image
+ [], # follow
+ [], # unfollow
[], # help
[], # clear
[], # quit
]
))
init_interactive_shell(d)
+ read_history()
reset()
while True:
if g['prefix']: