Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. playlist_name = raw_input("Enter playlist name: ")
  2.  
  3.  
  4. def get_share_token_by_playlist_name(input_playlist_name):
  5.     """
  6.    Function gets all user playlists and returns share token.
  7.    If playlist isn't found -> returns error message.
  8.    """
  9.     lists = api.get_all_playlists()
  10.     for i in range(len(lists)):
  11.         if lists[i]["name"] == input_playlist_name:
  12.             token = lists[i]["shareToken"]
  13.             return token
  14.     print "Playlist is not found or isn't shared."
  15.  
  16.  
  17. def get_share_token():
  18.     """
  19.    If share token is found -> returns token.
  20.    Else -> requests correct playlist name
  21.    """
  22.     global playlist_name
  23.  
  24.     while True:
  25.         if get_share_token_by_playlist_name(playlist_name):
  26.             token = get_share_token_by_playlist_name(playlist_name)
  27.             return token
  28.         else:
  29.             playlist_name = raw_input("Enter playlist name" +
  30.                                       " or print 'close' to exit: ")
  31.             if playlist_name == 'close':
  32.                 print 'Good Bye!'
  33.                 sleep(1)
  34.                 sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement