• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.prompt_for_user_token函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中spotipy.util.prompt_for_user_token函数的典型用法代码示例。如果您正苦于以下问题:Python prompt_for_user_token函数的具体用法?Python prompt_for_user_token怎么用?Python prompt_for_user_token使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了prompt_for_user_token函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: fit

    def fit(self, user_id):
        ''' 
        something really weird happening, number of artists collected from liza dropped
        from 400 to 308 with no changes in artist selection/deletion
        may have something to do with unicode? 
        Should double check getting all playlists
        Should double check that unicode items are not being removed ie /x etc
        moving on to creating full pipeline
        '''
        self.user_id = user_id
        self.token = util.prompt_for_user_token(user_id, scope = 'user-library-read', client_id = '530ddf60a0e840369395009076d9fde7', 
            client_secret = 'd1974e81df054fb2bffa895b741f96f6', redirect_uri = 'https://github.com/bsbell21')

        print 'token created'
        self.s = sp.Spotify(auth = self.token)

        # new code start - getting playlist authentication
        self.token_playlist = util.prompt_for_user_token(user_id, scope = 'playlist-modify-public', client_id = '530ddf60a0e840369395009076d9fde7', 
            client_secret = 'd1974e81df054fb2bffa895b741f96f6', redirect_uri = 'https://github.com/bsbell21')
        self.s_playlist = sp.Spotify(auth = self.token_playlist)
        self.s_playlist.trace = False
        # new code end

        #self.get_user_saved_tracks() -- old code
        user_playlists = self.get_user_public_playlists(user_id)
        df_pipeline, artist_data_echonest = self.get_playlist_data()
        return df_pipeline
开发者ID:bsbell21,项目名称:CapstoneProject,代码行数:27,代码来源:spotify_functions.py


示例2: getToken

def getToken(username, client_id, client_secret, redirect):
    try:
        token = util.prompt_for_user_token(username, 'playlist-modify-public', client_id, client_secret , redirect)

    except:
        #os.remove(f".cache-{username}")
        token = util.prompt_for_user_token(username, 'playlist-modify-public', client_id, client_secret, redirect)

    return token
开发者ID:luizpericolo,项目名称:fresh_script,代码行数:9,代码来源:fresh.py


示例3: generate_spotify_playlist

def generate_spotify_playlist(tracks, playlist_name, username):
    """
    Generates a Spotify playlist from the given tracks
    :param tracks: list of Track objects
    :param playlist_name: name of playlist to create
    :param username: Spotify username
    """
    sp = spotipy.Spotify()
    formatted_tracks = [u'artist:"{artist}" track:"{track}"'.format(artist=t.artist, track=t.track) for t in tracks]
    search_res = [sp.search(q=t, type='track', limit=1) for t in formatted_tracks]
    track_ids = [(first(r.get('tracks', {}).get('items', {})) or {}).get('uri') for r in search_res if
                 r.get('tracks', {}).get('items')]

    token = util.prompt_for_user_token(username, scope=scope)

    if token:
        sp = spotipy.Spotify(auth=token)
        sp.trace = False
        playlist = sp.user_playlist_create(username, playlist_name)

        if playlist and playlist.get('id'):
            sp.user_playlist_add_tracks(username, playlist.get('id'), track_ids)
            print "boom!"
    else:
        print "Can't get token for", username
开发者ID:NicholasRostant,项目名称:listentothis_onspotify,代码行数:25,代码来源:main.py


示例4: generate_spotify_playlist

def generate_spotify_playlist(tracks, playlist_name, username):
    """
    Generates a Spotify playlist from the given tracks
    :param tracks: list of Track objects
    :param playlist_name: name of playlist to create
    :param username: Spotify username
    """
    sp = spotipy.Spotify()
    formatted_tracks = []
    for t in tracks:
        try:
            formatted_tracks.append(u'artist:"{artist}" track:"{track}"'.format(artist=t.artist, track=t.track))
        except UnicodeDecodeError:
            pass
    search_res = [sp.search(q=t, type='track', limit=1) for t in formatted_tracks]
    track_ids = [(first(r.get('tracks', {}).get('items', {})) or {}).get('uri') for r in search_res if
                 r.get('tracks', {}).get('items')]

    token = util.prompt_for_user_token(username, scope=scope, client_id=SPOTIFY_API_KEY, client_secret=SPOTIFY_API_SECRET, redirect_uri=SPOTIFY_URI)

    if token:
        sp = spotipy.Spotify(auth=token)
        sp.trace = False
        playlist = sp.user_playlist_create(username, playlist_name)

        if playlist and playlist.get('id'):
            sp.user_playlist_add_tracks(username, playlist.get('id'), track_ids)
            print "Playlist has been processed."
    else:
        print "Can't get token for", username
开发者ID:rgero,项目名称:TopTracksFromLastFMtoSpotify,代码行数:30,代码来源:LastFM_Top_Tracks.py


示例5: createPlaylistForUser

def createPlaylistForUser(utp):
    if len(utp.spotify_recommended_tracks) == 0:
        print("Missing recommended tracks. Early return")
        return

    if utp.username == "":
        print("Fail. Need to run Setup first. Early return.")
        return

    print( "Login to Spotify as %s" % utp.username )
    scope = 'playlist-read-private user-top-read user-library-read playlist-modify-private playlist-modify-public'
    token = util.prompt_for_user_token(client_id=utp.clientId,
                                       client_secret=utp.clientSecret,
                                       redirect_uri=utp.redirect_uri,
                                       username=utp.username, scope=scope)

    if token:
        sp = spotipy.Spotify(auth=token)
        userId = sp.current_user()["id"]

        playlistsInitData = sp.user_playlist_create(userId, utp.createdPlaylistName)
        playlistId = playlistsInitData['id']
        #print(utp.spotify_recommended_tracks)
        response = sp.user_playlist_add_tracks(user=userId, playlist_id=playlistId, tracks=utp.spotify_recommended_tracks[:50]) # TODO this reduction influences a lot
        #print(response)

    else:
        print("Can't get token for %s", utp.username)
开发者ID:mgodek,项目名称:music_recommendation_system,代码行数:28,代码来源:spotify.py


示例6: favSpotifyArtists

def favSpotifyArtists():
	shortArtists, medArtists, longArtists = [], [], []

	if len(sys.argv) > 1:
		username = sys.argv[1]
	else:
		print("Usage: %s username" % (sys.argv[0],))
		sys.exit()

	scope = 'user-top-read'
	token = util.prompt_for_user_token(username, scope)

	if token:
		sp = spotipy.Spotify(auth=token)
		sp.trace = False
		ranges = ['short_term', 'medium_term', 'long_term']
		for range in ranges:
			#print "range:", range
			results = sp.current_user_top_artists(time_range=range, limit=50)
			for i, item in enumerate(results['items']):
				#print i, item['name']
				name = item['name']
				if name == 'short_term':
					shortArtists.append(name.encode("utf-8"))
					return shortArtists
				elif name == 'medium_term':
					medArtists.append(name.encode("utf-8"))
					return medArtists
		 		else:
					longArtists.append(name.encode("utf-8"))
					return longArtists
			print
	else:
		print("Can't get token for", username)
开发者ID:sujitshivaprasad,项目名称:ArtistsInTown,代码行数:34,代码来源:artistsInTown.py


示例7: handle

    def handle(self, *args, **options):
        username = options['username']
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            raise CommandError(u'User with username "{}" does not exist'.format(username))

        spotify_user = options['spotify_username']
        token = util.prompt_for_user_token(spotify_user,
                                           scope='playlist-read-private user-library-read user-follow-read')
        self.sp = spotipy.Spotify(auth=token)

        artists = set()
        artists.update(self.get_playlist_artists(spotify_user))
        artists.update(self.get_library_artists())
        artists.update(self.get_followed_artists())
        artists.discard('')

        for artist in artists:
            try:
                artist_obj = Artist.objects.get(name__iexact=artist)
            except Artist.DoesNotExist:
                artist_obj = Artist.objects.create(name=artist)
            ArtistRating.objects.get_or_create(artist=artist_obj, user=user,
                                               defaults={'rating': ArtistRating.RATING_UNRATED})
开发者ID:fotcorn,项目名称:liveinconcert2,代码行数:25,代码来源:spotify.py


示例8: fit

    def fit(self, user_ids, update = []):
        '''
        INPUT: list of user_ids, list of user_ids to update
        OUTPUT: DataFrame with listen data for all users' public playlists
        if update, will delete user data from database and repopulate it, else will look for data in database
        and use that if it exists
        '''
        #adding this as fix but want to remove
        self.token = util.prompt_for_user_token(self.my_id, 
            scope = 'playlist-modify-public user-library-read playlist-read-private playlist-modify-private user-library-modify', client_id = '530ddf60a0e840369395009076d9fde7', 
            client_secret = 'd1974e81df054fb2bffa895b741f96f6', redirect_uri = 'https://github.com/bsbell21')
        # remove above when you figure out expiration

        df_pipeline_list = []
        for user_id in user_ids:
            if user_id in update:
                df_pipeline_user = self.fit_one(user_id, update = True)
            else:
                df_pipeline_user = self.fit_one(user_id)

            if len(df_pipeline_user) > 0:
                df_pipeline_list.append(df_pipeline_user)


        df_pipeline_full = pd.concat(df_pipeline_list)#.reset_index()
        return df_pipeline_full
开发者ID:bsbell21,项目名称:weTunes,代码行数:26,代码来源:spotify_functions_mult131114.py


示例9: enumerate_playlists

def enumerate_playlists(username):

    scope = 'user-library-modify playlist-read-collaborative playlist-read-private'
    token = util.prompt_for_user_token(username=username,
                                       redirect_uri='http://localhost:8888/callback',
                                       scope=scope)

    if token:
        sp = spotipy.Spotify(auth=token)
        playlists = sp.user_playlists(username)
        for playlist in playlists['items']:
            if playlist['owner']['id']:
                print()
                print(playlist['name'])
                print('  total tracks', playlist['tracks']['total'])
                save_input = sync_playlist(playlist['name'])
                if save_input == 'Y' or save_input == 'y':
                    results = sp.user_playlist(username, playlist['id'], fields="tracks,next")
                    tracks = results['tracks']
                    j = 0
                    track_ids = []
                    for i, item in enumerate(tracks['items']):
                        track = item['track']
                        if j == 50:
                            sp.current_user_saved_tracks_add(track_ids)
                            track_ids.clear()
                            j = 0
                        track_ids.append(track['id'])
                        j += 1
                    sp.current_user_saved_tracks_add(track_ids)
    else:
        print("Can't get token for", username)
开发者ID:eghantous82,项目名称:scriptify,代码行数:32,代码来源:sync_my_tracks.py


示例10: collect_playlist_data

def collect_playlist_data(username, user_playlists):
  """
  Description:
    Collects and returns a list of track uri's extracted from the 
    given user's playlist. (Duplicates allowed)

  Arguments:
    username: username of the playlist
    playlist_name: name of playlist from which to extract track uri's

    Example: username = 'mlhopp' & user_playlists = ['coffee music', 'running']
  """
  # Getting token to access playlists
  token = util.prompt_for_user_token(username)
  if token:
    sp = spotipy.Spotify(auth=token)
    track_list = []
    for playlist_name in user_playlists:
      pl_id = get_playlist_id(sp, username, playlist_name)
      if not (pl_id == None):
        pl = sp.user_playlist(username, pl_id)
        # get all tracks from playlist
        pl = get_playlist_tracks(sp, username, pl_id)
        track_list.extend(get_playlist_track_uris(pl))
      else:
        print ("WARNING: No playlist by name \'%s \' for user \'%s\'\n" 
                % (playlist_name, username))
    return track_list
  else:
    print "Can't get token for", username 
    return None
开发者ID:nmusgrave,项目名称:Conducere,代码行数:31,代码来源:spotify.py


示例11: show_tracks

def show_tracks(results):
  for i, item in enumerate(tracks['items']):
        track = item['track']
        print ("   %d %32.32s %s" % (i, track['artists'][0]['name'],
            track['name']))

  if __name__ == '__main__':
    if len(sys.argv) > 1:
        username = sys.argv[1]
    else:
        print ("Need your username!")
        print ("usage: python user_playlists.py [username]")
        sys.exit()

    token = util.prompt_for_user_token(username)

    if token:
        sp = spotipy.Spotify(auth=token)
        playlists = sp.user_playlists(username)
        for playlist in playlists['items']:
            if playlist['owner']['id'] == username:
                print (playlist['name'])
                print ('  total tracks', playlist['tracks']['total'])
                results = sp.user_playlist(username, playlist['id'],
                    fields="tracks,next")
                tracks = results['tracks']
                show_tracks(tracks)
                while tracks['next']:
                    tracks = sp.next(tracks)
                    show_tracks(tracks)
    else:
        print ("Can't get token for", username)
开发者ID:MarinaMoskowitz,项目名称:dj-husky,代码行数:32,代码来源:pythonParty.py


示例12: make_playlist

def make_playlist(username, playlistName="Spoons&Tunes", genre="rock", location="Boston,MA", numSongs=20):
    scope = 'playlist-modify-public'

    token = util.prompt_for_user_token(username, scope,"2a1cd7b9a1ee4294b4085e52d2ac51a2", "e771e11a11f9444c906f6eccabf3a037","http://google.com")
    songList =  Music.getPlayList(genre, location, numSongs)
    spotify = spotipy.Spotify(auth=token)
    curlist = spotify.user_playlist_create(username,playlistName, public=True)
    
    songIDs = []
    
    for song in songList:
        
        #print song
        
        songDict = spotify.search(q='track:'+song.__str__(),limit=1,type='track')
        for i, t in enumerate(songDict['tracks']['items']):
            songIDs.append( t['external_urls']['spotify'])
            break

        #songDict = song.get_tracks('spotify-WW')[0]
        #id = songDict['foreign_id']
        #songIDs.append(id[14:])
        
    #print len(songIDs)
    
    
    spotify.user_playlist_add_tracks(username, curlist['id'], songIDs)
    
    return curlist['external_urls']['spotify']
开发者ID:sshankar19,项目名称:Spoons-Tunes,代码行数:29,代码来源:Spotify.py


示例13: _get_auth

 def _get_auth(self):
     return spotipy_util.prompt_for_user_token(
         username=self.username,
         client_id=self.client_id,
         client_secret=self.client_secret,
         redirect_uri='http://example.com/tunezinc/',
         scope=self.SCOPES,
     )
开发者ID:brentc,项目名称:tunezinc,代码行数:8,代码来源:spotify.py


示例14: get_token

 def get_token(self):
     scope = 'playlist-modify-private'
     return util.prompt_for_user_token(
         SPOTIFY_AUTH['USERNAME'],
         scope,
         client_id=SPOTIFY_AUTH['CLIENT_ID'],
         client_secret=SPOTIFY_AUTH['CLIENT_SECRET'],
         redirect_uri=SPOTIFY_AUTH['REDIRECT_URI'])
开发者ID:tomharvey,项目名称:3old3new,代码行数:8,代码来源:spotify_client.py


示例15: command_token

def command_token(args):
    token = util.prompt_for_user_token(args.username)
    if token:
        print token
        with open(os.path.expanduser('~/.playa'), 'w') as f:
            f.write(json.dumps({'token': token}))
    else:
        print "Can't get token for", args.username
开发者ID:zeekay,项目名称:playa,代码行数:8,代码来源:cli.py


示例16: get_token

 def get_token(username, scope):
     """Obtain an access token for the user."""
     token = util.prompt_for_user_token(
         username=username,
         scope=scope,
         client_id=os.environ['SPOTIPY_CLIENT_ID'],
         client_secret=os.environ['SPOTIPY_CLIENT_SECRET'],
         redirect_uri=os.environ['SPOTIPY_REDIRECT_URI'])
     return token
开发者ID:jlitven,项目名称:Remix-Finder,代码行数:9,代码来源:spotify_adaptors.py


示例17: get_connection

def get_connection(username, redirect_uri):
    token = util.prompt_for_user_token(username,
        SPOTIPY_SCOPE, client_id=SPOTIFY_CLIENT_ID,
        client_secret=SPOTIFY_CLIENT_SECRET, 
        redirect_uri=redirect_uri)
    if token:
        return spotipy.Spotify(auth=token)
    else:
        return spotipy.Spotify()
开发者ID:tchandler,项目名称:nostalgeist,代码行数:9,代码来源:__init__.py


示例18: __init__

 def __init__(self):
     self.user_saved_tracks = None
     self.m = msd.MSD_Queries()
     self.artist_data_echonest = None
     self.my_id = '1248440864' # will always use my id
     self.token = util.prompt_for_user_token(self.my_id, 
         scope = 'playlist-modify-public user-library-read playlist-read-private playlist-modify-private user-library-modify', client_id = '530ddf60a0e840369395009076d9fde7', 
         client_secret = 'd1974e81df054fb2bffa895b741f96f6', redirect_uri = 'https://github.com/bsbell21')
     self.s = sp.Spotify(auth = self.token)
开发者ID:bsbell21,项目名称:weTunes,代码行数:9,代码来源:spotify_functions_mult131114.py


示例19: _get_token

 def _get_token(self, scope):
     token = util.prompt_for_user_token(self.username,
                                        scope=scope,
                                        client_id=self.ws_key,
                                        client_secret=self.ws_secret,
                                        redirect_uri=self.redirect_uri)
     if not token:
         raise RuntimeError("Cannot get token for user %s" % self.username)
     return token
开发者ID:sdmac,项目名称:playlist-manager,代码行数:9,代码来源:spotify.py


示例20: seed

def seed(request):
    token = util.prompt_for_user_token(steve_spotify_id, 'playlist-modify-public')

    sp = spotipy.Spotify(token)
    playlists = sp.user_playlists(steve_spotify_id, limit=50)['items']
    for p in playlists:
        print p
        Playlist.objects.create(spotify_id=p['id'], user_id=steve_spotify_id, name=p['name'])
    return HttpResponse("seeded with steves playlists")
开发者ID:heinst,项目名称:playlists,代码行数:9,代码来源:views.py



注:本文中的spotipy.util.prompt_for_user_token函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python makeunicode.u函数代码示例发布时间:2022-05-27
下一篇:
Python sync.Sync类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap