-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_token.py
63 lines (52 loc) · 1.76 KB
/
user_token.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 Christopher C. Strelioff <[email protected]>
#
# Distributed under terms of the MIT license.
"""
user_token.py
=================
A Python 3 example of using the discogs-client with a user token.
"""
import discogs_client as dc
try:
# make sure there is a config.py file
import config
except:
raise Exception('Could not import config.py -- please create this file!')
# try to access the user token
utoken = config.user_token
if utoken == 'your-user-token-here':
raise Exception('Please set variaible user_token in config.py!\n'
'--obtain token at:'
' https://www.discogs.com/settings/developers')
uagent = ('UserTokenExample/0.1 '
'+https://github.com/cstrelioff/discogs-python3-examples')
print('\n===\n'
'user agent: {0}\n'
'user token: {1}\n'
'==='.format(uagent, utoken))
# Following the example here:
#
# https://github.com/discogs/discogs_client#user-token-authentication
#
d = dc.Client(uagent, user_token=utoken)
me = d.identity()
print('\n* Identity')
print('I\'m {0} ({1}) from {2}.'.format(me.name, me.username, me.location))
print('My wantlist has {} items.'.format(len(me.wantlist)))
print('\n* Fetching data')
results = d.search('Stockholm By Night', type='release')
print('results.pages:', results.pages)
artist = results[0].artists[0]
print('artist.name:', artist.name)
print('\n* Artist ID')
artist_id = artist.id
print('artist.id: {}'.format(artist_id))
print('d.artist({}): {}'.format(artist_id, d.artist(artist_id)))
print('\n* Drill down')
releases = d.search('Bit Shifter', type='artist')[0].releases[1].\
versions[0].labels[0].releases
print('len(releases): {}'.format(len(releases)))