-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (36 loc) · 1.17 KB
/
main.py
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
40
41
42
import zipfile
import os
from notion2md import *
from sys import argv
# run
def run(token, _url):
print("start export notion file")
try:
export_cli(token, _url, 1)
except:
print("export notion file fail checkout your token or url")
else:
print("finish export notion file")
print("start compress output dir ")
target = './notion2md_output'
compress(target, "notionExport.zip")
print("finish compress output dir to notionExport.zip")
print("start clean output dir")
os.system(" rm -rf ./notion2md_output")
print(" everything is done ")
# compress to zip
def compress(dir, file_name):
z = zipfile.ZipFile(file_name, 'w', zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(dir):
fpath = dirpath.replace(dir, '')
fpath = fpath and fpath + os.sep or ''
for filename in filenames:
z.write(os.path.join(dirpath, filename), fpath + filename)
z.close()
# check args
if len(argv) != 3:
print("miss args,you can run this script like 'python3 main.py token_v2 url' ")
else:
token_v2 = argv[1]
url = argv[2]
run(token_v2, url)