ready for deployment
This commit is contained in:
parent
fcd403044d
commit
2b36475272
14
backup.py
14
backup.py
@ -3,21 +3,17 @@ import fmframework.net.user as user
|
|||||||
|
|
||||||
import sys, datetime, os
|
import sys, datetime, os
|
||||||
|
|
||||||
def backupScrobbles():
|
def backupScrobbles(path):
|
||||||
userobj = user.User('sarsoo')
|
userobj = user.User('sarsoo')
|
||||||
|
|
||||||
scrobbles = userobj.getRecentTracks(pagelimit = 2)
|
scrobbles = userobj.getRecentTracks(pagelimit = 2)
|
||||||
|
|
||||||
path = sys.argv[1]
|
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)
|
csvwrite.exportScrobbles(scrobbles, path)
|
||||||
pathdir = os.path.dirname(totalpath)
|
|
||||||
if not os.path.exists(totalpath):
|
|
||||||
os.makedirs(totalpath)
|
|
||||||
|
|
||||||
csvwrite.exportScrobbles(scrobbles)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
backupScrobbles()
|
backupScrobbles(sys.argv[1])
|
||||||
|
@ -3,11 +3,11 @@ import datetime
|
|||||||
|
|
||||||
headers = ['track', 'album', 'artist', 'time', 'track id', 'album id', 'artist id']
|
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 = csv.DictWriter(fileobj, fieldnames = headers)
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
@ -15,9 +15,9 @@ def exportScrobbles(scrobbles):
|
|||||||
for track in scrobbles:
|
for track in scrobbles:
|
||||||
|
|
||||||
trackdict = {
|
trackdict = {
|
||||||
'track':track['name'],
|
'track':track['name'].replace(';', '_').replace(',', '_'),
|
||||||
'album':track['album']['#text'],
|
'album':track['album']['#text'].replace(';', '_').replace(',', '_'),
|
||||||
'artist':track['artist']['#text'],
|
'artist':track['artist']['#text'].replace(';', '_').replace(',', '_'),
|
||||||
'time': datetime.datetime.fromtimestamp(int(track['date']['uts'])),
|
'time': datetime.datetime.fromtimestamp(int(track['date']['uts'])),
|
||||||
'track id':track['mbid'],
|
'track id':track['mbid'],
|
||||||
'album id':track['album']['mbid'],
|
'album id':track['album']['mbid'],
|
||||||
|
Loading…
Reference in New Issue
Block a user