class TwitterCall(object):
def __init__(
- self, username, password, format, domain, uri="",
- agent="Python Twitter Tools"
- ):
+ self, username, password, format, domain, uri="", agent=None):
self.username = username
self.password = password
self.format = format
except AttributeError:
return TwitterCall(
self.username, self.password, self.format, self.domain,
- self.uri + "/" + k, self.agent
- )
+ self.uri + "/" + k, self.agent)
def __call__(self, **kwargs):
uri = self.uri
method = "GET"
The output will not be parsed in any way. It will be a raw string
of XML.
"""
- def __init__(self, email=None, password=None, format="json", domain="twitter.com"):
+ def __init__(
+ self, email=None, password=None, format="json", domain="twitter.com",
+ agent=None):
"""
Create a new twitter API connector using the specified
credentials (email and password). Format specifies the output
ACTIONS:
follow add the specified user to your follow list
friends get latest tweets from your friends (default action)
+ help print this help text that you are currently reading
leave remove the specified user from your following list
public get latest public tweets
replies get latest replies
from api import Twitter, TwitterError
+AGENT_STR = "Twitter Command-line Tool"
+
options = {
'email': None,
'password': None,
print " Or the user may not exist."
print " Sorry."
print
+ print e
else:
print af(options['action'], user).encode(sys.stdout.encoding, 'replace')
status = (statusTxt.encode('utf8', 'replace'))
twitter.statuses.update(status=status)
+class HelpAction(Action):
+ def __call__(self, twitter, options):
+ print __doc__
+
actions = {
'follow': FollowAction,
'friends': FriendsAction,
+ 'help': HelpAction,
'leave': LeaveAction,
'public': PublicAction,
'replies': RepliesAction,
if options['email'] and not options['password']:
options['password'] = getpass("Twitter password: ")
- twitter = Twitter(options['email'], options['password'])
+
+ twitter = Twitter(options['email'], options['password'], agent=AGENT_STR)
action = actions.get(options['action'], NoSuchAction)()
+
try:
doAction = lambda : action(twitter, options)