-
Notifications
You must be signed in to change notification settings - Fork 0
/
dgs_client.py
52 lines (43 loc) · 1.27 KB
/
dgs_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import time
import os
from discogs_client import Client
from discogs_client.exceptions import HTTPError
user_token = os.environ.get('DISCOGS_TOKEN')
dgs_client = Client('EventbriteTest/1.2.1', user_token=user_token)
class DiscoGSError(RuntimeError):
pass
def retryer(max_retries=10, timeout=5):
def wraps(func):
def inner(*args, **kwargs):
for i in range(max_retries):
try:
result = func(*args, **kwargs)
except HTTPError:
time.sleep(timeout)
continue
else:
return result
else:
raise DiscoGSError
return inner
return wraps
@retryer(max_retries=10, timeout=10)
def get_images(artist_id):
artist = dgs_client.artist(artist_id)
images = []
if artist.images:
images = [
{
'image': {
'url': image['resource_url'],
'width': image['width'],
'height': image['height'],
'thumb_width': 150,
'thumb_height': 150,
'thumb_url': image['uri150'],
'image_type': image['type'],
}
}
for image in artist.images
]
return images