Add final output, account for some errors
Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
This commit is contained in:
parent
1111246cc4
commit
797021bac2
16
lb_import.py
16
lb_import.py
@ -7,11 +7,23 @@ import sys
|
||||
|
||||
|
||||
def connect_client(auth_token):
|
||||
try:
|
||||
client = pylistenbrainz.ListenBrainz()
|
||||
client.set_auth_token(auth_token)
|
||||
except BaseException:
|
||||
print("Unable to connect to ListenBrainz.")
|
||||
return client
|
||||
|
||||
|
||||
def open_export(export_file):
|
||||
try:
|
||||
with open(export_file, 'r') as read_file:
|
||||
export_json = json.load(read_file)
|
||||
except FileNotFoundError:
|
||||
print("File does not exist.")
|
||||
return export_json
|
||||
|
||||
|
||||
def parse_listen(raw):
|
||||
listen = pylistenbrainz.Listen(
|
||||
track_name=raw['track_metadata']['track_name'],
|
||||
@ -45,8 +57,7 @@ def parse_listen(raw):
|
||||
|
||||
def main():
|
||||
client = connect_client(sys.argv[1])
|
||||
with open(sys.argv[2], 'r') as read_file:
|
||||
exported = json.load(read_file)
|
||||
exported = open_export(sys.argv[2])
|
||||
print("Opened file with {} listens, starting import...".format(len(exported)))
|
||||
imported = 0
|
||||
for raw_listen in exported:
|
||||
@ -67,6 +78,7 @@ def main():
|
||||
sleep(sleep_time)
|
||||
else:
|
||||
break
|
||||
print("\nSuccesfully imported {} listens.".format(imported))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user