2 Commits 26d9687ef8 ... 64e550a170

Author SHA1 Message Date
  Giedrius Statkevičius 64e550a170 libtn: switch to indexes in get_status() 8 years ago
  Giedrius Statkevičius 53c1b9427a libtn: switch to indexes in check_if_online() 8 years ago
1 changed files with 10 additions and 10 deletions
  1. 10 10
      libtn.py

+ 10 - 10
libtn.py

@@ -238,6 +238,7 @@ class NotifyApi(object):
         Returns a dictionary of tuples of format (status, formatted_msg)
         '''
         ret = {}
+        i = 0
 
         if len(chan) == 0:
             if self.verbose:
@@ -245,11 +246,10 @@ class NotifyApi(object):
                       file=sys.stderr)
             return ret
 
-        offset = 0
         cont = True
         while cont:
-            payload = {'channel': ','.join(chan), 'limit': LIMIT,
-                       'offset': offset}
+            payload = {'channel': ','.join(chan[i*LIMIT:(i+1)*LIMIT]), 'limit': LIMIT,
+                       'offset': 0}
             resp = self.access_kraken('/streams', payload)
             if resp is None or 'streams' not in resp:
                 break
@@ -258,8 +258,8 @@ class NotifyApi(object):
                 name = stream['channel']['name']
                 ret[name] = (True, repl(stream, name, self.fmt.user_message['on']))
 
-            offset = offset + LIMIT
-            cont = len(resp['streams']) > 0
+            i += 1
+            cont = i*LIMIT < len(chan)
 
         for name in chan:
             if name not in ret:
@@ -277,6 +277,7 @@ class NotifyApi(object):
         followed_chans = []
         ret = {}
         offset = 0
+        i = 0
 
         while True:
             fol = self.get_followed_channels({'offset': offset,
@@ -293,18 +294,17 @@ class NotifyApi(object):
             return ret
 
         cmd = '/streams'
-        offset = 0
         while True:
-            payload = {'channel': ','.join(name for name in followed_chans),
-                       'offset': offset, 'limit': LIMIT}
+            payload = {'channel': ','.join(followed_chans[i*LIMIT:(i+1)*LIMIT]),
+                       'offset': 0, 'limit': LIMIT}
             json = self.access_kraken(cmd, payload)
             if json and 'streams' in json:
                 for stream in json['streams']:
                     ret[stream['channel']['name']] = (True, stream)
 
-            if not json or (json and 'streams' in json and len(json['streams']) == 0):
+            i += 1
+            if i*LIMIT > len(followed_chans):
                 break
-            offset = offset + LIMIT
 
         for name in followed_chans:
             if name not in ret: