2019-03-16 02:34:09 +00:00
|
|
|
import csv
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
headers = ['track', 'album', 'artist', 'time', 'track id', 'album id', 'artist id']
|
|
|
|
|
2019-03-17 00:00:38 +00:00
|
|
|
def exportScrobbles(scrobbles, path):
|
2019-03-16 02:34:09 +00:00
|
|
|
|
2019-03-17 00:00:38 +00:00
|
|
|
date = str(datetime.datetime.now()).split(' ')[0]
|
2019-03-16 02:34:09 +00:00
|
|
|
|
2019-03-17 00:00:38 +00:00
|
|
|
with open('{}/{}_scrobbles.csv'.format(path, date), 'w') as fileobj:
|
2019-03-16 02:34:09 +00:00
|
|
|
|
|
|
|
writer = csv.DictWriter(fileobj, fieldnames = headers)
|
|
|
|
writer.writeheader()
|
|
|
|
|
|
|
|
for track in scrobbles:
|
|
|
|
|
|
|
|
trackdict = {
|
2019-03-17 00:00:38 +00:00
|
|
|
'track':track['name'].replace(';', '_').replace(',', '_'),
|
|
|
|
'album':track['album']['#text'].replace(';', '_').replace(',', '_'),
|
|
|
|
'artist':track['artist']['#text'].replace(';', '_').replace(',', '_'),
|
2019-03-16 02:34:09 +00:00
|
|
|
'time': datetime.datetime.fromtimestamp(int(track['date']['uts'])),
|
|
|
|
'track id':track['mbid'],
|
|
|
|
'album id':track['album']['mbid'],
|
|
|
|
'artist id':track['artist']['mbid']}
|
|
|
|
|
|
|
|
writer.writerow(trackdict)
|