Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixes for pagination

  • Loading branch information...
commit b6dbc29dd25f090da6f1d2a8205f9dec8ab90eb0 1 parent d995786
Stefan Wendler authored

Showing 1 changed file with 62 additions and 39 deletions. Show diff stats Hide diff stats

  1. +62 39 src/pyscmpd/scprovider.py
101 src/pyscmpd/scprovider.py
@@ -215,6 +215,7 @@ def retriveChildren(self):
215 215
216 216 try:
217 217
  218 + '''
218 219 lim = ResourceProvider.reqLimit
219 220 off = 0
220 221
@@ -225,26 +226,33 @@ def retriveChildren(self):
225 226
226 227 if len(groups) == 0:
227 228 break
  229 + '''
  230 + groups = ResourceProvider.sc.get("/groups", limit=ResourceProvider.reqLimit)
228 231
229   - for group in groups:
  232 + for group in groups:
230 233
231   - logging.info("processing group %s" % group.permalink)
  234 + logging.info("processing group %s" % group.permalink)
232 235
233   - g = Group(resource.ID_OFFSET + group.id, group.permalink,
234   - self.category + "/" + self.name)
235   - g.setMeta({"directory" : self.category + "/" + self.name + "/"
236   - + group.permalink})
237   - self.addChild(g)
  236 + g = Group(resource.ID_OFFSET + group.id, group.permalink,
  237 + self.category + "/" + self.name)
  238 + g.setMeta({"directory" : self.category + "/" + self.name + "/"
  239 + + group.permalink})
  240 + self.addChild(g)
238 241
239   - logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
240   - (group.uri, g.getId(), group.permalink))
241   -
242   - off = off + lim
  242 + logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
  243 + (group.uri, g.getId(), group.permalink))
  244 +
  245 + '''
  246 + if len(groups) < lim:
  247 + break
  248 + else:
  249 + off = off + lim
243 250
244 251 if off >= ResourceProvider.reqMaxitems:
245 252 logging.info("Maximum request offset exceeded limit of %d. Ending this request." %
246 253 ResourceProvider.reqMaxitems)
247 254 break
  255 + '''
248 256
249 257 except Exception as e:
250 258 logging.warn("Unable to retrive data for groups: %s" % `e`)
@@ -280,6 +288,7 @@ def retriveChildren(self):
280 288
281 289 try:
282 290
  291 + '''
283 292 lim = ResourceProvider.reqLimit
284 293 off = 0
285 294
@@ -287,34 +296,38 @@ def retriveChildren(self):
287 296
288 297 logging.info("Requesting page with limit=%d; offset=%d" % (lim, off))
289 298
290   - allUsers = ResourceProvider.sc.get("/users", limit=lim, offset=off)
291 299
292 300 if len(allUsers) == 0:
293 301 break
  302 + '''
  303 + allUsers = ResourceProvider.sc.get("/users", limit=ResourceProvider.reqLimit)
  304 + for user in allUsers:
  305 +
  306 + try:
294 307
295   - for user in allUsers:
296   -
297   - try:
298   -
299   - u = User(resource.ID_OFFSET + user.id, user.uri + "/tracks", user.permalink,
300   - user.username, self.category + "/" + self.name)
301   - u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
  308 + u = User(resource.ID_OFFSET + user.id, user.uri + "/tracks", user.permalink,
  309 + user.username, self.category + "/" + self.name)
  310 + u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
302 311
303   - self.addChild(u)
  312 + self.addChild(u)
304 313
305   - logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
306   - (user.uri, u.getId(), user.permalink))
  314 + logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
  315 + (user.uri, u.getId(), user.permalink))
307 316
308   - except Exception as e:
309   - logging.warn("Unable to retrive data for user: %s" % `e`)
  317 + except Exception as e:
  318 + logging.warn("Unable to retrive data for user: %s" % `e`)
310 319
311   - off = off + lim
  320 + '''
  321 + if len(allUsers) < lim:
  322 + break
  323 + else:
  324 + off = off + lim
312 325
313 326 if off >= ResourceProvider.reqMaxitems:
314 327 logging.info("Maximum request offset exceeded limit of %d. Ending this request." %
315 328 ResourceProvider.reqMaxitems)
316 329 break
317   -
  330 + '''
318 331 except Exception as e:
319 332 logging.warn("Unable to retrive data for URI users: %s" % `e`)
320 333
@@ -387,7 +400,10 @@ def retriveChildren(self):
387 400 logging.info("Successfully retrieved user data: id=%d; name=%s" %
388 401 (u.getId(), user.permalink))
389 402
390   - off = off + lim
  403 + if len(users) < lim:
  404 + break
  405 + else:
  406 + off = off + lim
391 407
392 408 if off >= ResourceProvider.reqMaxitems:
393 409 logging.info("Maximum request offset exceeded limit of %d. Ending this request." %
@@ -445,26 +461,34 @@ def retriveChildren(self):
445 461 break
446 462
447 463 for track in tracks:
448   - tr = Track(resource.ID_OFFSET + track.id, track.stream_url, track.permalink)
449   - tr.setMeta({
450   - "file" : self.category + "/" + self.name + "/" + track.permalink,
451   - "Artist" : self.artist,
452   - "Title" : track.title,
453   - "Time" : track.duration})
454 464
455   - children.append(tr)
  465 + try:
  466 +
  467 + tr = Track(resource.ID_OFFSET + track.id, track.stream_url, track.permalink)
  468 + tr.setMeta({
  469 + "file" : self.category + "/" + self.name + "/" + track.permalink,
  470 + "Artist" : self.artist,
  471 + "Title" : track.title,
  472 + "Time" : track.duration})
  473 +
  474 + children.append(tr)
456 475
457   - logging.debug("Added track to user [%s]: %s" % (self.getName(), track.title))
  476 + logging.debug("Added track to user [%s]: %s" % (self.getName(), track.title))
458 477
459   - off = off + lim
  478 + except:
  479 + logging.warn("Unable to add track (no stream URL): %s" % track.title)
  480 +
  481 + if len(tracks) < lim:
  482 + break
  483 + else:
  484 + off = off + lim
460 485
461 486 if off >= ResourceProvider.reqMaxitems:
462 487 logging.info("Maximum request offset exceeded limit of %d. Ending this request." %
463 488 ResourceProvider.reqMaxitems)
464 489 break
465 490
466   - except Exception as e:
467   -
  491 + except:
468 492 logging.warn("Unable to retrive tracks for [%s]" % self.getName())
469 493
470 494 logging.info("Retrieved %d tracks for user [%s]" % (len(children), self.getName()))
@@ -478,4 +502,3 @@ def getStreamUri(self):
478 502 stream_url = ResourceProvider.sc.get(self.location, allow_redirects=False)
479 503 logging.debug("Stream url for URI %s is %s" % (self.location, stream_url.location))
480 504 return stream_url.location
481   -

0 comments on commit b6dbc29

Please sign in to comment.
Something went wrong with that request. Please try again.