comparison musixmatch-master/7digital-python/app.py @ 7:8c29444cb5fd

Just did some work
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Sat, 20 Apr 2013 19:01:57 +0200
parents
children
comparison
equal deleted inserted replaced
2:e0a7176da80a 7:8c29444cb5fd
1 import pickle
2 from lib.oauth7digital import Oauth7digital
3
4
5 TOKEN_FILE = './access_token.pkl'
6
7 def test_sevendigital():
8 try:
9 pkl_file = open(TOKEN_FILE, 'rb')
10 access_token = pickle.load(pkl_file)
11 pkl_file.close()
12 except:
13 access_token = None
14 if access_token:
15 print 'You have an access token: %s' % str(access_token.key)
16 else:
17 auth = Oauth7digital(CONSUMER_KEY, CONSUMER_SECRET)
18
19 token = auth.request_token()
20 authorized = auth.authorize_request_token(token)
21 access_token = auth.request_access_token(token)
22
23 pkl_file=open(TOKEN_FILE, 'wb')
24 pickle.dump(access_token, pkl_file)
25 pkl_file.close()
26
27 return access_token
28
29 def test_locker():
30 access_token = test_sevendigital()
31
32 sevendigital = Oauth7digital(CONSUMER_KEY, CONSUMER_SECRET, access_token)
33 results = sevendigital.get_locker()
34 for i in results:
35 print "-----------------------------"
36 print i.release.title
37 print i.release.artist.name
38 for a in i.tracks:
39 print a.track.title
40 return results
41
42 # app entry point
43 if __name__ == '__main__':
44 test_locker()
45 print 'Done.'
46
47
48