forked from tweepy/tweepy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtweepyshell
executable file
·43 lines (34 loc) · 1.1 KB
/
tweepyshell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
from getpass import getpass
from optparse import OptionParser
import tweepy
from tweepy import API, BasicAuthHandler
"""Launch an interactive shell ready for Tweepy usage
This script is handy for debugging tweepy during development
or to just play around with the library.
It imports tweepy and creates an authenticated API instance (api)
using the credentials provided.
"""
opt = OptionParser(usage='tweepyshell [options] <username> <password>')
opt.add_option('-d', '--debug',
action='store_true',
dest='debug',
help='enable debug mode')
options, args = opt.parse_args()
if len(args) == 1:
auth = BasicAuthHandler(args[0], getpass())
elif len(args) == 2:
auth = BasicAuthHandler(args[0], args[1])
else:
auth = None
if options.debug:
tweepy.debug()
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)