-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (29 loc) · 991 Bytes
/
main.py
File metadata and controls
39 lines (29 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from time import strftime
import json
import zipfile
from nswebdav.sync import NutstoreDav
with open("config.json", "r", encoding="utf-8") as f:
res = json.load(f)
login = res["login"]
password = res["password"]
dirpath = res["dirpath"]
print("Load Config Successfully")
dav = NutstoreDav()
dav.config(auth_tuple=(login, password))
time = strftime(" %Y-%m-%d,%H-%M-%S")
for path in dirpath:
target = os.path.basename(path) + time + ".zip"
f = zipfile.ZipFile(target, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(path):
fpath = root.replace(path, '')
for file in files:
f.write(os.path.join(root, file), os.path.join(fpath, file))
f.close()
print(f"Make {target} Zipfile Successfully")
with open(target, "rb") as f:
dav.mkdir("/Minecraft")
dav.upload(f.read(), "/Minecraft/" + target)
dav.close()
print("Backup successfully!")
os.system("pause")