]> jfr.im git - z_archive/twitter.git/commitdiff
Fix rate command. Though nobody uses it.
authorMike Verdone <redacted>
Wed, 14 Nov 2012 22:33:58 +0000 (23:33 +0100)
committerMike Verdone <redacted>
Wed, 14 Nov 2012 22:33:58 +0000 (23:33 +0100)
twitter/api2.py
twitter/cmdline.py

index 120b1a40aee9cbf54d4017da5346fb45d2811249..d9663b94d6df202af4f6c57fcd93d6f2d88ff7be 100644 (file)
@@ -98,7 +98,7 @@ class TwitterAPIError(TwitterError):
 
 
 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)
@@ -148,8 +148,8 @@ def make_url(secure, host, api_ver, path, params):
                 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)
index 299a132e68726ba3d199f90eec9e343cbd18e526..de5bea9c0cb10211970f73f09ff983e6196ccadf 100644 (file)
@@ -121,8 +121,8 @@ def parse_args(args, options):
                  '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'):
@@ -470,7 +470,7 @@ class SetStatusAction(Action):
     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:
@@ -499,6 +499,7 @@ class SetStatusAction(Action):
         if options['invert_split']:
             splitted.reverse()
         for status in splitted:
+            print(type(status))
             twitter.post("statuses/update", status=status)
 
 class TwitterShell(Action):
@@ -566,10 +567,13 @@ class DoNothingAction(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,