-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotify.py
279 lines (273 loc) · 17.5 KB
/
spotify.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import spotipy
import pandas as pd
from spotipy.oauth2 import SpotifyClientCredentials
from sklearn.preprocessing import StandardScaler
cid = '5410e774c83040bb85936efc4672828a'
secret = 'e893db8c750a439489d6a8c11560e470'
client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret)
token = 'BQARlBD1Twwg25QoI8atjUFjp3onciGdH6nw0dBHIqg_7RzIcrvb8hBswE2xTx4WJkLSOjSyB9VEeOIRDI3enJTdPVvJztOMz-FoUrYHNSEykr4NW6Rc7lwb6kZujQTN-tcG0lCKFog9BF3nhcb-xnAVsAi-KIw'
spotify = spotipy.Spotify(token)
def get_track_name(trackId):
return spotify.track(trackId)['name']
def get_acoustic_feature(trackId, featureName):
return spotify.audio_features(trackId)[0][featureName]
def get_track_artist(trackId):
return spotify.track(trackId)['album']['artists'][0]['name']
# labelled dataset
dataset = [{"genre": "eerie", "trackId" : "3Ot8c1sAmARXl31ZckeMDR"},
{"genre": "eerie", "trackId" : "4Sf5gXjMvciYzNGSrQx7BK"},
{"genre": "eerie", "trackId" : "0I1NIj3YZVJHv92HVG0aIV"},
{"genre": "eerie", "trackId" : "3n69hLUdIsSa1WlRmjMZlW"},
{"genre": "eerie", "trackId" : "3cKLaUSHmIW66lbEkpGDTX"},
{"genre": "eerie", "trackId" : "4mBA0FHbLRbGXAqQJBepUb"},
{"genre": "eerie", "trackId" : "4Adp5ixl3CJLBkCxGZWGUC"},
{"genre": "gritty", "trackId" : "441TUCOSya3kCQR1yeBxqH"},
{"genre": "gritty", "trackId" : "1oXaJxH9fv7dReSU99RPhg"},
{"genre": "gritty", "trackId" : "6RHHbAbyIcPpvS1dP3KUGq"},
{"genre": "gritty", "trackId" : "7daBwTiPNOVgoMUG4SICgh"},
{"genre": "gritty", "trackId" : "7zeCIWu37bKFJuem8MTyM1"},
{"genre": "gritty", "trackId" : "2J4QIV77CWoIWN6IY2u6pC"},
{"genre": "gritty", "trackId" : "1FKJs710WCc0ke0oPlwVOp"},
{"genre": "gritty", "trackId" : "6Q1xNxPaRewcWICHQXcdfH"},
{"genre": "melancholy", "trackId" : "0bPP8TKUIto1T9CAIoHONw"},
{"genre": "melancholy", "trackId" : "1rN9QoVxw5U7TJkyaUR8C1"},
{"genre": "melancholy", "trackId" : "1fvRueeK5f60hkG1VzoXXq"},
{"genre": "melancholy", "trackId" : "4AmcmraFjVzFb9SQDNTRyl"},
{"genre": "melancholy", "trackId" : "15Ax8eHs3aH9MCFcIERDp8"},
{"genre": "melancholy", "trackId" : "2v4lwSzPGMG2G8DOLSinuK"},
{"genre": "melancholy", "trackId" : "3C3YNkWdulBcyKGShi0v8q"},
{"genre": "melancholy", "trackId" : "0yc6Gst2xkRu0eMLeRMGCX"},
{"genre": "peaceful", "trackId" : "7mcM8OVEmqyTbUvO1in0oZ"},
{"genre": "peaceful", "trackId" : "3xr8COed4nPPn6XWZ0iCGr"},
{"genre": "peaceful", "trackId" : "7K6LFPfjdnN6QqvGzhvpRO"},
{"genre": "peaceful", "trackId" : "3pGTGFLKTGFOLArMq3H9jE"},
{"genre": "peaceful", "trackId" : "1g2eirb8uaYn54iEYZl3CS"},
{"genre": "peaceful", "trackId" : "1boXOL0ua7N2iCOUVI1p9F"},
{"genre": "peaceful", "trackId" : "7iBSkXB0pTvZasOLf0Qxk9"},
{"genre": "hopeful", "trackId" : "4kP7BPJ1d3WUGhykQBVEjH"},
{"genre": "hopeful", "trackId" : "3g9mw4A8vdljOKgwrit88g"},
{"genre": "hopeful", "trackId" : "5uIYONgpUQ7t0v7D6CTMBt"},
{"genre": "hopeful", "trackId" : "7D49Iig0avHre9RFSUMkd2"},
{"genre": "hopeful", "trackId" : "79irqIr5JmGSHeLtu8tntd"},
{"genre": "hopeful", "trackId" : "6KuHjfXHkfnIjdmcIvt9r0"},
{"genre": "hopeful", "trackId" : "6cMswWRv4lAU3mh5lclgCc"},
{"genre": "hopeful", "trackId" : "630sXRhIcfwr2e4RdNtjKN"},
{"genre": "hopeful", "trackId" : "6pWgRkpqVfxnj3WuIcJ7WP"},
{"genre": "adventure", "trackId" : "6pWgRkpqVfxnj3WuIcJ7WP"},
{"genre": "adventure", "trackId" : "3cYae8wCFw8T2j1sTw04gj"},
{"genre": "adventure", "trackId" : "2CVPSrJEWFbdtZysiAC9bO"},
{"genre": "adventure", "trackId" : "0dJDJQuaPaHrTCnU975oVb"},
{"genre": "adventure", "trackId" : "2gCyJ1tPvAR85o1M3X9FxA"},
{"genre": "adventure", "trackId" : "0DleZw1u3Tj13174MvwhFr"},
{"genre": "adventure", "trackId" : "4ac9hiXX0NXsBrecSvIvli"},
{"genre": "adventure", "trackId" : "0RJBK9LayfZbJOM7mc7cgF"},
{"genre": "adventure", "trackId" : "5Hroj5K7vLpIG4FNCRIjbP"},
{"genre": "adventure", "trackId" : "69uxyAqqPIsUyTO8txoP2M"},
{"genre": "dystopia", "trackId" : "1Fwj0wThn3kTg8D7KgWdsU"},
{"genre": "dystopia", "trackId" : "26fVjoeuhEAsAxmPzfTRIo"},
{"genre": "dystopia", "trackId" : "0boS4e6uXwp3zAvz1mLxZS"},
{"genre": "dystopia", "trackId" : "4vWeIrIQQrbThS11ogLTmu"},
{"genre": "dystopia", "trackId" : "6zLq4lYSu2W7LLxJlUWzz8"},
{"genre": "dystopia", "trackId" : "416MsJxvxSKY96DCmbJIRs"},
{"genre": "dystopia", "trackId" : "70p3HYq9iHZisJqpDmWd1U"},
{"genre": "dystopia", "trackId" : "5orAKrVdrk1kPtTa7zNvYL"},
{"genre": "light_academia", "trackId" : "657XjY28KTNbkgkKxN4xtN"},
{"genre": "light_academia", "trackId" : "7LRAg8a4Q5PrPHSGBfng22"},
{"genre": "light_academia", "trackId" : "4w0sBSIgy945h7TZE0FUbc"},
{"genre": "light_academia", "trackId" : "3tJjZMHLqhD8DaGgdBICnc"},
{"genre": "light_academia", "trackId" : "1HYnjKqSSHh1tdl2Hi57zH"},
{"genre": "light_academia", "trackId" : "0MNNKSUU9OOQ8DSGWduw79"},
{"genre": "light_academia", "trackId" : "4k7x3QKrc3h3U0Viqk0uop"},
{"genre": "gothic", "trackId" : "4NZKQIAbpUPd0jn0CzvRpS"},
{"genre": "gothic", "trackId" : "22TntnVO3lQNDR5nsvxGRs"},
{"genre": "gothic", "trackId" : "7xfSCgVOkQJhVxnqzepATH"},
{"genre": "gothic", "trackId" : "7otCGmgp9h4CsR2LhwB6gt"},
{"genre": "gothic", "trackId" : "6V46LfMpdJWfhDImW2JT7t"},
{"genre": "gothic", "trackId" : "1UWhx0pFZccP4jdCIZsj7U"},
{"genre": "gothic", "trackId" : "6EfZCB2wudriyD1vDjuAZ9"},
{"genre": "gothic", "trackId" : "1JI9psoqJuAvUQqGUn6gKJ"},
{"genre": "epic", "trackId" : "0ZUMBOzlwNXfVE4Z8lSrsd"},
{"genre": "epic", "trackId" : "6nDpNDwRckcKnv8iEpajA1"},
{"genre": "epic", "trackId" : "6UarreObk00TgLO7HleEYj"},
{"genre": "epic", "trackId" : "1Cx4BHHSPutUiuvcr1vY79"},
{"genre": "epic", "trackId" : "0eS3M71hhN3qx8HAy72lQC"},
{"genre": "epic", "trackId" : "3jqcJNacs1yDhtMk0wckxv"},
{"genre": "epic", "trackId" : "5e6g37Ez3Yl9DD5Lzekn13"},
{"genre": "epic", "trackId" : "1CXffruI5PpH4KCd2M7Vp5"},
{"genre": "epic", "trackId" : "0CFg32QX1Omtxx20kXhvml"},
{"genre": "epic", "trackId" : "3eyxh8xkW0X7k1FSHlAatt"},
{"genre": "epic", "trackId" : "4m5gJuQlo2byPHRQamL6dd"},
{"genre": "epic", "trackId" : "5orAKrVdrk1kPtTa7zNvYL"},
{"genre": "epic", "trackId" : "3aLcJuAarDz0kzxcdSbAYc"},
{"genre": "epic", "trackId" : "27iksNpaur1CcH0w8703by"},
{"genre": "battle", "trackId" : "00PqDQBmhtTT7x2DWruzA5"},
{"genre": "battle", "trackId" : "0MEKVOZBNHfoD7Ex5k2j4Z"},
{"genre": "battle", "trackId" : "3x87uypJR7497bJidQJNnT"},
{"genre": "battle", "trackId" : "4VaOecssBTF02dO0n2u8BS"},
{"genre": "battle", "trackId" : "5glKprpzpGW5Pf4wB9gNPq"},
{"genre": "battle", "trackId" : "6NuT12xM2tDj64vJkmcsCw"},
{"genre": "battle", "trackId" : "0QEMA67GIanMItxiHsILxO"},
{"genre": "battle", "trackId" : "0udtq3sZLerXwvHq4diyN3"},
{"genre": "battle", "trackId" : "5IzZpz0vA73IIjqFPpXSXP"},
{"genre": "suspense", "trackId" : "1NUHxg3L7gEvXk4b7Oj93r"},
{"genre": "suspense", "trackId" : "2mkv1b3dRFyiJ4Ybq31owf"},
{"genre": "suspense", "trackId" : "1gqCO3x2MO4KbQfN9pGUlH"},
{"genre": "suspense", "trackId" : "2gbrU8NMsUrOdCTJ53yH4M"},
{"genre": "suspense", "trackId" : "3HxKGK3LiVk1TFq3GCEA4S"},
{"genre": "suspense", "trackId" : "3mRKzC7Tycb2O8Z4k3XrZP"},
{"genre": "suspense", "trackId" : "568iUWeGqw9CWkvLI5k0Hd"},
{"genre": "suspense", "trackId" : "7lnTzVtcGkEFwMHcw8MNjl"},
{"genre": "dreamy", "trackId" : "3lAun9V0YdTlCSIEXPvfsY"},
{"genre": "dreamy", "trackId" : "6JxNli46YwzPdPiHnEQUeC"},
{"genre": "dreamy", "trackId" : "2TgxCUZdHFkPEVmFge1OSd"},
{"genre": "dreamy", "trackId" : "7D0RhFcb3CrfPuTJ0obrod"},
{"genre": "dreamy", "trackId" : "1IbgYIuVwJsibCcT5GFYHy"},
{"genre": "dreamy", "trackId" : "6S7o12almFeL57rbRvdY5l"},
{"genre": "dreamy", "trackId" : "6dwNcWigdxPUcqfz2zM6GL"},
{"genre": "elegant", "trackId" : "0pHFAoFikRaLe6tUMbB9FT"},
{"genre": "elegant", "trackId" : "6MQAB3vorg90FA3tQpbYXK"},
{"genre": "elegant", "trackId" : "2YGckbcAmjxbiZbYVAz5UW"},
{"genre": "elegant", "trackId" : "09GXY43KLwv7zNdI2LREhx"},
{"genre": "elegant", "trackId" : "0hqj5JBnFt1BHEz2UCFwrl"},
{"genre": "elegant", "trackId" : "1lxC8oDMNaxfhhseIThJGg"},
{"genre": "elegant", "trackId" : "6ABHr8kYCws5z6gC9Lwith"},
{"genre": "elegant", "trackId" : "54KFQB6N4pn926IUUYZGzK"},
{"genre": "sensual", "trackId" : "6KyafpXji3NKMmlmSokT9Y"},
{"genre": "sensual", "trackId" : "2cLOhJv1hQQRLBf3eVJOHV"},
{"genre": "sensual", "trackId" : "60ynsPSSKe6O3sfwRnIBRf"},
{"genre": "sensual", "trackId" : "4Zgo9uf4jURl7tjCBmUjy2"},
{"genre": "sensual", "trackId" : "2Xr1dTzJee307rmrkt8c0g"},
{"genre": "sensual", "trackId" : "3Ty7OTBNSigGEpeW2PqcsC"},
{"genre": "sensual", "trackId" : "6Zjw7NdXuLiwULHgyJ0Jk8"},
{"genre": "sensual", "trackId" : "7iCeaYJSEdGWeFNTAEqUzJ"},
{"genre": "sensual", "trackId" : "3M0lSi5WW79CXQamgSBIjx"},
{"genre": "ethereal", "trackId" : "5G5ogjmnQxSQG9cskbNEse"},
{"genre": "ethereal", "trackId" : "4q4Iau9NfuxYo36uQiVv02"},
{"genre": "ethereal", "trackId" : "3BuFzaaIPQHAFqPubPzcIO"},
{"genre": "ethereal", "trackId" : "00PXRPuZFlM5dv1FeJa69J"},
{"genre": "ethereal", "trackId" : "1RgiH5ucgoEWDKmGyA5drQ"},
{"genre": "ethereal", "trackId" : "27z0lLzmteOnv7kN2DGmUp"},
{"genre": "ethereal", "trackId" : "1Qr17u2S9kNDzTeWAJCY5N"},
{"genre": "ethereal", "trackId" : "1CVfctMJ63tqZUC2VZqdMa"},
{"genre": "tragedy", "trackId" : "0u2P5u6lvoDfwTYjAADbn4"},
{"genre": "tragedy", "trackId" : "6VObnIkLVruX4UVyxWhlqm"},
{"genre": "tragedy", "trackId" : "1PInWkBARsxLyouDqa2GtF"},
{"genre": "tragedy", "trackId" : "4pvb0WLRcMtbPGmtejJJ6y"},
{"genre": "tragedy", "trackId" : "7aBxPIMXWjcemfrslbqyA9"},
{"genre": "tragedy", "trackId" : "5FKnuwsKf7YFpmhA5Wnl0q"},
{"genre": "tragedy", "trackId" : "2PYKNn068cvGI3Aqrzhn5V"},
{"genre": "tragedy", "trackId" : "79jYT83v4bMOWEgwjQxSx2"},
{"genre": "tragedy", "trackId" : "0C1RaT1eyqvoeqskbaTg3E"},
{"genre": "tragedy", "trackId" : "75rLEwEhMEy9UbIg7iA7ay"},
{"genre": "tragedy", "trackId" : "3XZwNBKgscdvmBgHl12pib"},
{"genre": "tragedy", "trackId" : "5c9qm0bMYawSyRNUTmUMs5"},
{"genre": "tragedy", "trackId" : "7C8dJ4bWha4y0J1z5xuJMa"},
{"genre": "sentimental", "trackId" : "4VJIS7iuc4hA6Aw5qSwvAF"},
{"genre": "sentimental", "trackId" : "75RJeZlyiKqlYk0s5pKPR6"},
{"genre": "sentimental", "trackId" : "2Kz5qeXifBxE0zmuoVchlM"},
{"genre": "sentimental", "trackId" : "5r09ZUBR3ZPOAr0feB2j4G"},
{"genre": "sentimental", "trackId" : "1eCRwOFNJG8ax7bTBBECDd"},
{"genre": "sentimental", "trackId" : "75JFxkI2RXiU7L9VXzMkle"},
{"genre": "sentimental", "trackId" : "3R5jAYJeAlKS7dxCLWpHNv"},
{"genre": "sentimental", "trackId" : "4dF0mDPTlpjThf1mJyK83B"},
{"genre": "sentimental", "trackId" : "7zmrZMinkTMJ2kZgM9Kqgp"},
{"genre": "sentimental", "trackId" : "2I0LNCqlQpAPJlwOEWaefE"},
{"genre": "sentimental", "trackId" : "0lPVImvleVXxm3wMZ4by57"},
{"genre": "urban", "trackId" : "0zsOsqDGi0li2EYTFV15eO"},
{"genre": "urban", "trackId" : "6MRuNaMaH65vGyek33fXMV"},
{"genre": "urban", "trackId" : "7Le0iFjogJUWzKpHSTZ11q"},
{"genre": "urban", "trackId" : "0djfvA3c8AxxlQolu6zn6K"},
{"genre": "urban", "trackId" : "0RiRZpuVRbi7oqRdSMwhQY"},
{"genre": "urban", "trackId" : "5zsHmE2gO3RefVsPyw2e3T"},
{"genre": "urban", "trackId" : "2XSrt1dcuOXPgl3B4bxmBz"},
{"genre": "urban", "trackId" : "61JIqvw8uxHqdmWfUDAWEU"},
{"genre": "urban", "trackId" : "19xIkK0geTHrEkeBiQMDL1"},
{"genre": "urban", "trackId" : "6sHeshKZ58cV5mjC5m3mW8"},
{"genre": "romance", "trackId" : "7aely3H8kMj9o0gt6vXHE1"},
{"genre": "romance", "trackId" : "1Xi84slp6FryDSCbzq4UCD"},
{"genre": "romance", "trackId" : "0aIW3ekrhK1eh3BYCh11op"},
{"genre": "romance", "trackId" : "7B5Npv8NjjTCzk8PLpU66h"},
{"genre": "romance", "trackId" : "7i9RIEuPvpQ8NtfI0dSJeK"},
{"genre": "romance", "trackId" : "2IOFZdYYkFxEHVz1w34PoL"},
{"genre": "romance", "trackId" : "44AyOl4qVkzS48vBsbNXaC"},
{"genre": "romance", "trackId" : "2eIk5ky8THuVeQg5Z5eVav"},
{"genre": "romance", "trackId" : "15xWRPHQMeqgdkGzInx3PY"},
{"genre": "romance", "trackId" : "6lanRgr6wXibZr8KgzXxBl"},
{"genre": "romance", "trackId" : "4oa14QBfWRDfJy2agySy0L"},
{"genre": "romance", "trackId" : "1RMJOxR6GRPsBHL8qeC2ux"},
{"genre": "romance", "trackId" : "5HgYrY0MHqt5Iwd2aRR0xh"},
{"genre": "romance", "trackId" : "4IouQaO9GkaHC7AtMErdSa"},
{"genre": "slice_of_life", "trackId" : "5mOOwyOGev9frlXm5NDEQy"},
{"genre": "slice_of_life", "trackId" : "0pj90Ajg2NmdZalF67DfOF"},
{"genre": "slice_of_life", "trackId" : "5bO33fxvcGqZp7Pw3zIQsj"},
{"genre": "slice_of_life", "trackId" : "0I0l2Oo5zjpCEphpDJL0Pm"},
{"genre": "slice_of_life", "trackId" : "17s9ohMleXceK8Qobgl8Zd"},
{"genre": "slice_of_life", "trackId" : "20j7l6tFtc5lynXpbOQg1O"},
{"genre": "slice_of_life", "trackId" : "26dXOkhzMxLLNaUXt77HQc"},
{"genre": "slice_of_life", "trackId" : "0eu4C55hL6x29mmeAjytzC"},
{"genre": "slice_of_life", "trackId" : "3afkJSKX0EAMsJXTZnDXXJ"},
{"genre": "coming_of_age", "trackId" : "2MvvoeRt8NcOXWESkxWn3g"},
{"genre": "coming_of_age", "trackId" : "6ixkZ2Q9gQeh52C6GxbETg"},
{"genre": "coming_of_age", "trackId" : "4RvWPyQ5RL0ao9LPZeSouE"},
{"genre": "coming_of_age", "trackId" : "0GO8y8jQk1PkHzS31d699N"},
{"genre": "coming_of_age", "trackId" : "3TgMcrV32NUKjEG2ujn9eh"},
{"genre": "coming_of_age", "trackId" : "0w5Bdu51Ka25Pf3hojsKHh"},
{"genre": "coming_of_age", "trackId" : "79e2GU4RLPjAqnijfvsXYr"},
{"genre": "coming_of_age", "trackId" : "0ZcQUwVyXgpUepJsvgOYgk"},
{"genre": "coming_of_age", "trackId" : "4MnDLNhqL6HuSzFO4b4rvJ"},
{"genre": "coming_of_age", "trackId" : "0Hrd6CSafHHqKptyFppmqH"},
{"genre": "cyberpunk", "trackId" : "2zAi85TQB7mLzl8P1ySAj9"},
{"genre": "cyberpunk", "trackId" : "57JRZbE80MLsYbmb24cPee"},
{"genre": "cyberpunk", "trackId" : "018SQDupRTRsl1Wolu1X0c"},
{"genre": "cyberpunk", "trackId" : "1r5zaKfwOz92HaXXLExw7u"},
{"genre": "cyberpunk", "trackId" : "6Ylxg3Xx9H3XqYrXGW5VKX"},
{"genre": "cyberpunk", "trackId" : "7a0FMMOewudf9673dtW0zf"},
{"genre": "cyberpunk", "trackId" : "7mMlbJlXXo2mRtQ4R9sIzD"},
{"genre": "cyberpunk", "trackId" : "6c6fQ8k4yIUnLJEPy7zj3z"},
{"genre": "cyberpunk", "trackId" : "3IICGfnISboAKaSudbZqPk"},
{"genre": "supernatural", "trackId" : "49qEikVVPd6PgH6S2pbXjZ"},
{"genre": "supernatural", "trackId" : "60jI0JgMLLj1VggHJVhtRs"},
{"genre": "supernatural", "trackId" : "5qaLfqAUiqvsoL0l4T05Yx"},
{"genre": "supernatural", "trackId" : "6uSdrEiGAARej0o6Noi5Cx"},
{"genre": "supernatural", "trackId" : "1n8NKQRg8LVHy7oUhUgbFF"},
{"genre": "supernatural", "trackId" : "3gW27yBKGV7eC4XWzZLnn7"},
{"genre": "supernatural", "trackId" : "4qFJ2lSwXMDXk0zd92iFsQ"},
{"genre": "supernatural", "trackId" : "56xv2AYPZj746eVaSPgq5i"},
{"genre": "supernatural", "trackId" : "0a6dYP49uFEAHe15tIXZU2"},
{"genre": "eccentric", "trackId" : "37mfTcSlX60JtAvAETytGs"},
{"genre": "eccentric", "trackId" : "3lPr8ghNDBLc2uZovNyLs9"},
{"genre": "eccentric", "trackId" : "6OMYrlY0ioFeC0y3SUjNLp"},
{"genre": "eccentric", "trackId" : "2Y0iGXY6m6immVb2ktbseM"},
{"genre": "eccentric", "trackId" : "5iDp87PwrUT0tgCReHVdOV"},
{"genre": "eccentric", "trackId" : "2x5r1IvquyZ2pu36HyoutB"},
{"genre": "eccentric", "trackId" : "67BtfxlNbhBmCDR2L2l8qd"},
{"genre": "eccentric", "trackId" : "3Wgs96Z4TdCpnqFj2CxpsI"},
{"genre": "eccentric", "trackId" : "0yTJtxZJ5VLfBEHhiNUNeY"},
]
# return data as [genre, track_name, artist, track_id, acousticness, danceability, energy, instrumentalness,
# key, liveness, loudness, mode, speechiness, tempo, time_signature, valence]
data = [[]]
for i in dataset:
genre = i.get("genre")
trackId = i.get("trackId")
data.append([genre, get_track_name(trackId), get_track_artist(trackId), trackId,
get_acoustic_feature(trackId, 'acousticness'),
get_acoustic_feature(trackId, 'danceability'),
get_acoustic_feature(trackId, 'energy'),
get_acoustic_feature(trackId, 'instrumentalness'),
get_acoustic_feature(trackId, 'key'),
get_acoustic_feature(trackId, 'liveness'),
get_acoustic_feature(trackId, 'loudness'),
get_acoustic_feature(trackId, 'mode'),
get_acoustic_feature(trackId, 'speechiness'),
get_acoustic_feature(trackId, 'tempo'),
get_acoustic_feature(trackId, 'time_signature'),
get_acoustic_feature(trackId, 'valence')
])
# create pandas DataFrame
df = pd.DataFrame(data, columns = ['genre', 'track_name', 'artist','track_id', 'acousticness', 'danceability', 'energy',
'instrumentalness', 'key', 'liveness', 'loudness', 'mode', 'speechiness',
'tempo', 'time_signature', 'valence'])
# export to csv file
df.to_csv(r'C:\Users\Afrah\Desktop\inTune\datset.csv', index=False)
print(df)