tweepyshell: add support for IPython, with fallback to code.interact
authorGergely Imreh <imrehg@gmail.com>
Fri, 19 Mar 2010 02:21:05 +0000 (10:21 +0800)
committerGergely Imreh <imrehg@gmail.com>
Fri, 19 Mar 2010 02:24:55 +0000 (10:24 +0800)
IPython is a much versatile interactive shell compared to code,
use it's power if awailable.

Signed-off-by: Gergely Imreh <imrehg@gmail.com>
tweepyshell

index eefb85aa2c910e721c35fce942ea23d9aa2cc0b9..6ba854df2354ae0300a91f343c778c6612948e6f 100755 (executable)
@@ -2,7 +2,6 @@
 
 import sys
 
-import code
 from getpass import getpass
 from optparse import OptionParser
 import tweepy
@@ -33,5 +32,14 @@ else:
 if options.debug:
     tweepy.debug()
 
-code.interact('<Tweepy shell>', local={'tweepy': tweepy, 'api': API(auth)})
+local_ns = {'tweepy': tweepy, 'api': API(auth)}
+shellbanner = '<Tweepy shell>'
+
+try:
+    import IPython
+    ipshell = IPython.Shell.IPShell(user_ns = local_ns)
+    ipshell.mainloop(sys_exit=1, banner = shellbanner)
+except ImportError:
+    import code
+    code.interact(shellbanner, local = local_ns)