-
Notifications
You must be signed in to change notification settings - Fork 0
/
discogsObject.py
132 lines (115 loc) · 3.91 KB
/
discogsObject.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
__author__ = 'Mike'
import json
import discogsPy3
import time
class DiscogsObject():
def __init__(self,page):
self.data = json.loads(page)
for item in self.data:
self.createProperty(item)
def createProperty(self,keyToGet):
setattr(self,keyToGet,self.data[keyToGet])
class Artist(DiscogsObject):
def __init__(self,page,client):
DiscogsObject.__init__(self,page)
self.client = client
def releases(self):
final_releases = []
release_page = self.client.retrieve_page(self.resource_url + "/releases")
releases = json.loads(release_page)
for item in releases['releases']:
try:
new_release = self.client.release_by_id(item['main_release'])
final_releases.append(new_release)
time.sleep(1)
except:
pass
return final_releases
def group_list(self):
final_groups = []
for item in self.groups:
try:
new_group = self.client.artist_by_id(item['id'])
final_groups.append(new_group)
time.sleep(1)
except:
pass
return final_groups
def member_list(self):
final_members = []
for item in self.members:
try:
new_member = self.client.artist_by_id(item['id'])
final_members.append(new_member)
time.sleep(1)
except:
pass
return final_members
class Master(DiscogsObject):
def __init__(self,page,client):
DiscogsObject.__init__(self,page)
self.client = client
def artist_list(self):
final_artists = []
for item in self.artists:
try:
new_artist = self.client.artist_by_id(item['id'])
final_artists.append(new_artist)
time.sleep(1)
except:
pass
return final_artists
def artist(self):
final_artists = []
this_artist = self.client.artist_by_id(self.artists[0]['id'])
return this_artist
class Release(DiscogsObject):
def __init__(self,page,client):
DiscogsObject.__init__(self,page)
self.client = client
def artist_list(self):
final_artists = []
for item in self.artists:
try:
new_artist = self.client.artist_by_id(item['id'])
final_artists.append(new_artist)
time.sleep(1)
except:
pass
return final_artists
def artist(self):
final_artists = []
this_artist = self.client.artist_by_id(self.artists[0]['id'])
return this_artist
def label_list(self):
final_labels = []
for item in self.labels:
try:
new_label = self.client.label_by_id(item['id'])
final_labels.append(new_label)
time.sleep(1)
except:
pass
return final_labels
class Label(DiscogsObject):
def __init__(self,page,client):
DiscogsObject.__init__(self,page)
self.client = client
def releases(self,pages=1):
final_releases = []
release_page = self.client.retrieve_page(self.resource_url + "/releases")
releases = json.loads(release_page)
max_pages = releases['pagination']['pages']
if pages > max_pages:
pages = max_pages
for x in range(0,pages):
release_page = self.client.retrieve_page(self.resource_url + "/releases?page=" + str(x))
releases = json.loads(release_page)
for item in releases['releases']:
try:
new_release = self.client.release_by_id(item['id'])
final_releases.append(new_release)
time.sleep(1)
except:
pass
return final_releases