mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Aligned export and backup
This commit is contained in:
parent
b41203bac7
commit
b7781d27c3
@ -1,5 +1,5 @@
|
||||
import tarfile
|
||||
from datetime import datetime
|
||||
import time
|
||||
import glob
|
||||
import os
|
||||
from ...globalconf import dir_settings
|
||||
@ -36,16 +36,16 @@ def backup(targetfolder=None,include_images=False):
|
||||
log("Creating backup...")
|
||||
|
||||
|
||||
now = datetime.utcnow()
|
||||
timestr = now.strftime("%Y_%m_%d_%H_%M_%S")
|
||||
timestr = time.strftime("%Y_%m_%d_%H_%M_%S")
|
||||
filename = f"maloja_backup_{timestr}.tar.gz"
|
||||
archivefile = os.path.join(targetfolder,filename)
|
||||
assert not os.path.exists(archivefile)
|
||||
with tarfile.open(name=archivefile,mode="x:gz") as archive:
|
||||
outputfile = os.path.join(targetfolder,filename)
|
||||
assert not os.path.exists(outputfile)
|
||||
|
||||
with tarfile.open(name=outputfile,mode="x:gz") as archive:
|
||||
for category, filelist in real_files.items():
|
||||
for f in filelist:
|
||||
p = PurePath(f)
|
||||
r = p.relative_to(dir_settings[category])
|
||||
archive.add(f,arcname=os.path.join(category,r))
|
||||
log("Backup created: " + col['yellow'](archivefile))
|
||||
return archivefile
|
||||
log("Backup created: " + col['yellow'](outputfile))
|
||||
return outputfile
|
||||
|
@ -6,12 +6,19 @@ from doreah.io import col
|
||||
|
||||
from ...database.sqldb import get_scrobbles
|
||||
|
||||
def export(targetfolder="."):
|
||||
def export(targetfolder=None):
|
||||
|
||||
outputfile = os.path.join(targetfolder,f"maloja_export_{time.strftime('%Y%m%d')}.json")
|
||||
if targetfolder is None:
|
||||
targetfolder = os.getcwd()
|
||||
|
||||
timestr = time.strftime("%Y_%m_%d_%H_%M_%S")
|
||||
filename = f"maloja_export_{timestr}.json"
|
||||
outputfile = os.path.join(targetfolder,filename)
|
||||
assert not os.path.exists(outputfile)
|
||||
|
||||
data = {'scrobbles':get_scrobbles()}
|
||||
with open(outputfile,'w') as outfd:
|
||||
json.dump(data,outfd,indent=3)
|
||||
|
||||
print(f"Exported {len(data['scrobbles'])} Scrobbles to {col['yellow'](outputfile)}")
|
||||
return outputfile
|
||||
|
Loading…
Reference in New Issue
Block a user