Print more informtion, implement increasing sleep on failure

Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
This commit is contained in:
Abdulkadir Furkan Şanlı 2021-11-17 11:31:17 +01:00
parent a4e56f7a9e
commit 1111246cc4
Signed by: afk
GPG Key ID: C8F00588EE6ED1FE

View File

@ -47,19 +47,24 @@ def main():
client = connect_client(sys.argv[1]) client = connect_client(sys.argv[1])
with open(sys.argv[2], 'r') as read_file: with open(sys.argv[2], 'r') as read_file:
exported = json.load(read_file) exported = json.load(read_file)
print("Opened file, starting import...") print("Opened file with {} listens, starting import...".format(len(exported)))
imported = 0
for raw_listen in exported: for raw_listen in exported:
listen = parse_listen(raw_listen) listen = parse_listen(raw_listen)
for x in range(0, 5): for x in range(0, 5):
try: try:
client.submit_single_listen(listen) client.submit_single_listen(listen)
imported = imported + 1
print("Imported {} listens.".format(imported), end='\r')
submit_error = None submit_error = None
except BaseException: except BaseException:
submit_error = True submit_error = True
if submit_error: if submit_error:
print("Error occurred, retrying in 5 seconds...") sleep_time = x * 5
sleep(5) print(
"\nError occurred, retrying in {} seconds...".format(sleep_time))
sleep(sleep_time)
else: else:
break break