view Yading/7digital-python/app.py @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 8c29444cb5fd
children
line wrap: on
line source
import pickle
from lib.oauth7digital import Oauth7digital


TOKEN_FILE = './access_token.pkl'

def test_sevendigital():
    try:
        pkl_file = open(TOKEN_FILE, 'rb')
        access_token = pickle.load(pkl_file)
        pkl_file.close()
    except:
        access_token = None
    if access_token:
        print 'You have an access token: %s' % str(access_token.key)
    else:
        auth = Oauth7digital(CONSUMER_KEY, CONSUMER_SECRET)

        token = auth.request_token()
        authorized = auth.authorize_request_token(token)
        access_token = auth.request_access_token(token)
        
        pkl_file=open(TOKEN_FILE, 'wb')
        pickle.dump(access_token, pkl_file)
        pkl_file.close()
        
    return access_token
        
def test_locker():
    access_token = test_sevendigital()
    
    sevendigital = Oauth7digital(CONSUMER_KEY, CONSUMER_SECRET, access_token)
    results = sevendigital.get_locker()
    for i in results:
        print "-----------------------------"
        print i.release.title
        print i.release.artist.name
        for a in i.tracks:
            print a.track.title
    return results

# app entry point
if __name__ == '__main__':
    test_locker()
    print 'Done.'