Clean api code
Clean up the formatting.
This commit is contained in:
parent
dad5a3709d
commit
dc4e83b133
14
api_calls.py
14
api_calls.py
@ -18,7 +18,7 @@ def get_mb_id(artist_name, mb_confidence):
|
||||
else:
|
||||
print("No artist found.")
|
||||
return False, "", True
|
||||
elif (response.status_code == 503):
|
||||
elif response.status_code == 503:
|
||||
sleep(1)
|
||||
return False, "", False
|
||||
else:
|
||||
@ -30,7 +30,7 @@ def get_image(mb_id, ftv_api_key, artist_path):
|
||||
response = requests.get(ftv_api_url)
|
||||
ftv_data =response.json()
|
||||
if not ('status' in ftv_data):
|
||||
if ('artistthumb' in ftv_data):
|
||||
if 'artistthumb' in ftv_data:
|
||||
art_url = ftv_data['artistthumb'][0]['url']
|
||||
print(art_url)
|
||||
response = requests.get(art_url)
|
||||
@ -38,14 +38,14 @@ def get_image(mb_id, ftv_api_key, artist_path):
|
||||
with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f:
|
||||
f.write(response.content)
|
||||
return True
|
||||
elif ('artistbackground' in ftv_data):
|
||||
elif 'artistbackground' in ftv_data:
|
||||
art_url = ftv_data['artistbackground'][0]['url']
|
||||
response = requests.get(art_url)
|
||||
if (response.status_code == 200):
|
||||
if response.status_code == 200:
|
||||
with open(os.path.join(artist_path, 'artist.jpg'),'wb') as f:
|
||||
f.write(response.content)
|
||||
return True
|
||||
elif ('hdmusiclogo' in ftv_data):
|
||||
elif 'hdmusiclogo' in ftv_data:
|
||||
art_url = ftv_data['hdmusiclogo'][0]['url']
|
||||
response = requests.get(art_url)
|
||||
if response.status_code == 200:
|
||||
@ -58,12 +58,12 @@ def get_image(mb_id, ftv_api_key, artist_path):
|
||||
else:
|
||||
print("Thumb not found.")
|
||||
return True
|
||||
elif (response.status_code == 503):
|
||||
elif response.status_code == 503:
|
||||
sleep(1)
|
||||
return False
|
||||
else:
|
||||
error_msg = ftv_data['error message']
|
||||
if (error_msg == "503"):
|
||||
if error_msg == "503":
|
||||
sleep(1)
|
||||
return False
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user