Skip to content

Instantly share code, notes, and snippets.

@johndavidsimmons
Created July 12, 2017 17:30
Show Gist options
  • Select an option

  • Save johndavidsimmons/3e498aafa3228bd63a4f749dc60d242a to your computer and use it in GitHub Desktop.

Select an option

Save johndavidsimmons/3e498aafa3228bd63a4f749dc60d242a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import discogs_client
import os
d = discogs_client.Client('John_Python_API_Test/0.1')
if os.path.exists('.env'):
for line in open(".env"):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
d.set_consumer_key(
os.environ.get("CONSUMER_KEY"),
os.environ.get("CONSUMER_SECRET")
)
black_sabbath = d.artist(144998)
formats = [
u'Album', u'Single', u'EP',
u'7"', u"45 RPM", u'10"',
u"LP", u"33 ⅓ RPM", u"12"
]
class Record(object):
def __init__(self, obj):
self.title = obj.title
self.formats_dict = obj.formats.pop()
@property
def is_vinyl(self):
global formats
try:
if u'Compilation' in self.formats_dict.get('descriptions'):
return False
if self.formats_dict.get(u'name') == "Vinyl":
return True
elif any(i in self.formats_dict.get('descriptions') for i in formats):
return True
except:
return False
def main():
for i in black_sabbath.releases:
if i.__class__.__name__ == "Release":
rec = Record(i)
if rec.is_vinyl:
print(i)
elif i.__class__.__name__ == "Master":
for v in i.versions:
rec = Record(v)
if rec.is_vinyl:
print(v)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment