-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_feat_playlists_new_albums.py
More file actions
42 lines (31 loc) · 1.41 KB
/
Copy pathget_feat_playlists_new_albums.py
File metadata and controls
42 lines (31 loc) · 1.41 KB
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
import django
import os
from spotipy.oauth2 import SpotifyClientCredentials
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "music.settings")
django.setup()
from spotify_app.models import Playlists
import spotipy
import time
def main():
client_credentials_manager = SpotifyClientCredentials(client_id='5fe40e82ba784e6e8c10e465af890764',
client_secret='40fa3b85075c45e88877adf8d562fb38')
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
print('Getting featured playlists...')
payload = sp.featured_playlists()['playlists']
# print(payload)
playlist_total = payload['items']
while payload['next']:
payload = sp.next(payload)
playlist_total.extend(payload['items'])
for playlist in playlist_total:
temp_obj = Playlists(playlist_id=playlist['id'],
playlist_name=playlist['name'],
playlist_url=playlist['external_urls']['spotify'],
playlist_num_tracks=playlist['tracks']['total'],
playlist_featured=True,
playlist_owner=playlist['owner']['display_name'].lower(),
date_created=time.time(),
playlist_img_src=playlist['images'][0]['url'])
temp_obj.save()
if __name__ == '__main__':
main()