~aleteoryx/bcdl

8f9dbae6598e028f55e458d949a1f723f797d82e — Aleteoryx 2 months ago 0f1bf5f
make the iteration code less ugly
1 files changed, 10 insertions(+), 13 deletions(-)

M playback2scrob.py
M playback2scrob.py => playback2scrob.py +10 -13
@@ 159,7 159,6 @@ def api_call(method: str, *, post=False, **params):
	if 'error' in res:
		raise APIException(method, res['error'], res['message'])

	print(res)
	return res

def put_scrobbles(sk: str, scrobbles: List[Scrobble]):


@@ 216,18 215,16 @@ while True:

sk = session['session']['key']

acc = []
for scrobble in scrobbles:
	acc.append(scrobble)
	if len(acc) < 50:
		continue
	put_scrobbles(sk, acc)
	acc = []
	print("sent 50 scrobbles...")
scrobbles = [*scrobbles]
fulllen = len(scrobbles)
count = 0
while len(scrobbles) > 0:
	batch = scrobbles[:50]
	scrobbles = scrobbles[50:]
	put_scrobbles(sk, batch)
	count += len(batch)
	print(f"sent {count}/{fullen} scrobbles...", end="\r")
	sleep(5)

if len(acc) > 0:
	put_scrobbles(sk, acc)
	print(f"sent {len(acc)} scrobbes...")

print()
print("done!")