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
|
import tarfile
|
||||||
from datetime import datetime
|
import time
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
from ...globalconf import dir_settings
|
from ...globalconf import dir_settings
|
||||||
@ -36,16 +36,16 @@ def backup(targetfolder=None,include_images=False):
|
|||||||
log("Creating backup...")
|
log("Creating backup...")
|
||||||
|
|
||||||
|
|
||||||
now = datetime.utcnow()
|
timestr = time.strftime("%Y_%m_%d_%H_%M_%S")
|
||||||
timestr = now.strftime("%Y_%m_%d_%H_%M_%S")
|
|
||||||
filename = f"maloja_backup_{timestr}.tar.gz"
|
filename = f"maloja_backup_{timestr}.tar.gz"
|
||||||
archivefile = os.path.join(targetfolder,filename)
|
outputfile = os.path.join(targetfolder,filename)
|
||||||
assert not os.path.exists(archivefile)
|
assert not os.path.exists(outputfile)
|
||||||
with tarfile.open(name=archivefile,mode="x:gz") as archive:
|
|
||||||
|
with tarfile.open(name=outputfile,mode="x:gz") as archive:
|
||||||
for category, filelist in real_files.items():
|
for category, filelist in real_files.items():
|
||||||
for f in filelist:
|
for f in filelist:
|
||||||
p = PurePath(f)
|
p = PurePath(f)
|
||||||
r = p.relative_to(dir_settings[category])
|
r = p.relative_to(dir_settings[category])
|
||||||
archive.add(f,arcname=os.path.join(category,r))
|
archive.add(f,arcname=os.path.join(category,r))
|
||||||
log("Backup created: " + col['yellow'](archivefile))
|
log("Backup created: " + col['yellow'](outputfile))
|
||||||
return archivefile
|
return outputfile
|
||||||
|
@ -6,12 +6,19 @@ from doreah.io import col
|
|||||||
|
|
||||||
from ...database.sqldb import get_scrobbles
|
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()}
|
data = {'scrobbles':get_scrobbles()}
|
||||||
with open(outputfile,'w') as outfd:
|
with open(outputfile,'w') as outfd:
|
||||||
json.dump(data,outfd,indent=3)
|
json.dump(data,outfd,indent=3)
|
||||||
|
|
||||||
print(f"Exported {len(data['scrobbles'])} Scrobbles to {col['yellow'](outputfile)}")
|
print(f"Exported {len(data['scrobbles'])} Scrobbles to {col['yellow'](outputfile)}")
|
||||||
|
return outputfile
|
||||||
|
Loading…
Reference in New Issue
Block a user