ready for deployment

This commit is contained in:
aj 2019-03-17 00:00:38 +00:00
parent fcd403044d
commit 2b36475272
2 changed files with 11 additions and 15 deletions

View File

@ -3,21 +3,17 @@ import fmframework.net.user as user
import sys, datetime, os
def backupScrobbles():
def backupScrobbles(path):
userobj = user.User('sarsoo')
scrobbles = userobj.getRecentTracks(pagelimit = 2)
path = sys.argv[1]
datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/')
if not os.path.exists(path):
os.makedirs(path)
totalpath = os.path.join(path, datepath)
pathdir = os.path.dirname(totalpath)
if not os.path.exists(totalpath):
os.makedirs(totalpath)
csvwrite.exportScrobbles(scrobbles)
csvwrite.exportScrobbles(scrobbles, path)
if __name__ == '__main__':
backupScrobbles()
backupScrobbles(sys.argv[1])

View File

@ -3,11 +3,11 @@ import datetime
headers = ['track', 'album', 'artist', 'time', 'track id', 'album id', 'artist id']
def exportScrobbles(scrobbles):
def exportScrobbles(scrobbles, path):
date = str(datetime.datetime.now())
date = str(datetime.datetime.now()).split(' ')[0]
with open('scrobbles.csv', 'w') as fileobj:
with open('{}/{}_scrobbles.csv'.format(path, date), 'w') as fileobj:
writer = csv.DictWriter(fileobj, fieldnames = headers)
writer.writeheader()
@ -15,9 +15,9 @@ def exportScrobbles(scrobbles):
for track in scrobbles:
trackdict = {
'track':track['name'],
'album':track['album']['#text'],
'artist':track['artist']['#text'],
'track':track['name'].replace(';', '_').replace(',', '_'),
'album':track['album']['#text'].replace(';', '_').replace(',', '_'),
'artist':track['artist']['#text'].replace(';', '_').replace(',', '_'),
'time': datetime.datetime.fromtimestamp(int(track['date']['uts'])),
'track id':track['mbid'],
'album id':track['album']['mbid'],