class TwitterAPI(object):
- def __init__(self, domain='api.twitter.com', api_version='1.1', auth=NoAuth(),
+ def __init__(self, domain='api.twitter.com', api_version='1.1', auth=None,
secure=True, stream=False, return_raw_response=False):
"""
`host` host to connect to (api.twitter.com)
raise TwitterError("Missing parameter for ':{}'".format(param))
param = str(params.pop(param[1:]))
real_params.append(param)
- real_path = '/'.join(real_params)
- api_ver_str = '{}/'.format(str(api_ver)) if api_ver is not None else ""
+ real_path = u'/'.join(real_params)
+ api_ver_str = u'{}/'.format(str(api_ver)) if api_ver is not None else ""
secure_str = 's' if secure else ''
url = 'http{}://{}/{}{}.json'.format(secure_str, host, str(api_ver_str),
real_path)
'datestamp', 'no-ssl']
short_opts = "e:p:f:h?rR:c:l:td"
opts, extra_args = getopt(args, short_opts, long_opts)
- #extra_args = [arg.decode(locale.getpreferredencoding())
- # for arg in extra_args]
+ extra_args = [arg.decode(locale.getpreferredencoding())
+ for arg in extra_args]
for opt, arg in opts:
if opt in ('-f', '--format'):
def __call__(self, twitter, options):
statusTxt = (" ".join(options['extra_args'])
if options['extra_args']
- else str(input("message: ")))
+ else input("message: "))
replies = []
ptr = re.compile("@[\w_]+")
while statusTxt:
if options['invert_split']:
splitted.reverse()
for status in splitted:
+ print(type(status))
twitter.post("statuses/update", status=status)
class TwitterShell(Action):
class RateLimitStatus(Action):
def __call__(self, twitter, options):
- rate = twitter.get("account/rate_limit_status")
- print("Remaining API requests: %s / %s (hourly limit)" % (rate['remaining_hits'], rate['hourly_limit']))
- print("Next reset in %ss (%s)" % (int(rate['reset_time_in_seconds']-time.time()),
- time.asctime(time.localtime(rate['reset_time_in_seconds']))))
+ rate = twitter.get("application/rate_limit_status")
+ for res in rate['resources'].values():
+ for k, r in res.items():
+ print("Resource: {}".format(k))
+ print(" Remaining API requests: %s / %s (hourly limit)" % (r['remaining'], r['limit']))
+ print(" Next reset in %ss (%s)" % (int(r['reset']-time.time()),
+ time.asctime(time.localtime(r['reset']))))
actions = {
'authorize' : DoNothingAction,