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:
|
else:
|
||||||
print("No artist found.")
|
print("No artist found.")
|
||||||
return False, "", True
|
return False, "", True
|
||||||
elif (response.status_code == 503):
|
elif response.status_code == 503:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
return False, "", False
|
return False, "", False
|
||||||
else:
|
else:
|
||||||
@ -30,7 +30,7 @@ def get_image(mb_id, ftv_api_key, artist_path):
|
|||||||
response = requests.get(ftv_api_url)
|
response = requests.get(ftv_api_url)
|
||||||
ftv_data =response.json()
|
ftv_data =response.json()
|
||||||
if not ('status' in ftv_data):
|
if not ('status' in ftv_data):
|
||||||
if ('artistthumb' in ftv_data):
|
if 'artistthumb' in ftv_data:
|
||||||
art_url = ftv_data['artistthumb'][0]['url']
|
art_url = ftv_data['artistthumb'][0]['url']
|
||||||
print(art_url)
|
print(art_url)
|
||||||
response = requests.get(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:
|
with open(os.path.join(artist_path, 'artist.jpg'), 'wb') as f:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
return True
|
return True
|
||||||
elif ('artistbackground' in ftv_data):
|
elif 'artistbackground' in ftv_data:
|
||||||
art_url = ftv_data['artistbackground'][0]['url']
|
art_url = ftv_data['artistbackground'][0]['url']
|
||||||
response = requests.get(art_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:
|
with open(os.path.join(artist_path, 'artist.jpg'),'wb') as f:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
return True
|
return True
|
||||||
elif ('hdmusiclogo' in ftv_data):
|
elif 'hdmusiclogo' in ftv_data:
|
||||||
art_url = ftv_data['hdmusiclogo'][0]['url']
|
art_url = ftv_data['hdmusiclogo'][0]['url']
|
||||||
response = requests.get(art_url)
|
response = requests.get(art_url)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@ -58,12 +58,12 @@ def get_image(mb_id, ftv_api_key, artist_path):
|
|||||||
else:
|
else:
|
||||||
print("Thumb not found.")
|
print("Thumb not found.")
|
||||||
return True
|
return True
|
||||||
elif (response.status_code == 503):
|
elif response.status_code == 503:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
error_msg = ftv_data['error message']
|
error_msg = ftv_data['error message']
|
||||||
if (error_msg == "503"):
|
if error_msg == "503":
|
||||||
sleep(1)
|
sleep(1)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user