-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify_api_data_extract.py
30 lines (22 loc) · 1011 Bytes
/
spotify_api_data_extract.py
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
import json
import os
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import boto3
from datetime import datetime
def lambda_handler(event, context):
cilent_id = os.environ.get('client_id')
client_secret = os.environ.get('client_secret')
client_credentials_manager = SpotifyClientCredentials(client_id=cilent_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager)
playlists = sp.user_playlists('spotify')
playlist_link = "https://open.spotify.com/playlist/37i9dQZEVXbNG2KDcFcKOF?si=1333723a6eff4b7f"
playlist_URI = playlist_link.split("/")[-1].split("?")[0]
spotify_data = sp.playlist_tracks(playlist_URI)
cilent = boto3.client('s3')
filename = "spotify_raw_" + str(datetime.now()) + ".json"
cilent.put_object(
Bucket="spotify-etl-project-darshil",
Key="raw_data/to_processed/" + filename,
Body=json.dumps(spotify_data)
)