-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb_dump.py
86 lines (68 loc) · 2.63 KB
/
db_dump.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# author: delta1037
# Date: 2022/01/11
# mail:geniusrabbit@qq.com
import logging
import NotionDump
from NotionDump.Dump.database import Database
from NotionDump.Dump.dump import Dump
from NotionDump.Notion.Notion import NotionQuery
from NotionDump.utils import common_op
TOKEN_TEST = "secret_ALjbBRGaZcagEjPtL1c2F139steBXjr8Fc8uQso4YLV"
DB_TABLE_INLINE_ID = "0b1f524ad42b420f889a2c6adb9b8c92"
NotionDump.DUMP_MODE = NotionDump.DUMP_MODE_DEBUG
# 解析数据库内容测试:根据token和id解析数据库内容,得到临时CSV文件
def test_db_table_inline_parser_dic(query):
db_handle = Database(
database_id=DB_TABLE_INLINE_ID,
query_handle=query,
export_child_pages=False
)
# 将解析内容存储到文件中;返回内容存储为json文件
page_detail_json = db_handle.dump_to_file()
print("json output to db_parser_result")
common_op.save_json_to_file(
handle=page_detail_json,
json_name=".tmp/db_parser_result.json"
)
print(db_handle.dump_to_dic())
# 解析数据库内容测试:根据token和id解析数据库内容,得到临时CSV文件
def test_db_table_inline_parser_csv(query, export_child=False):
db_handle = Dump(
dump_id=DB_TABLE_INLINE_ID,
query_handle=query,
export_child_pages=export_child,
dump_type=NotionDump.DUMP_TYPE_DB_TABLE
)
# 将解析内容存储到文件中;返回内容存储为json文件
page_detail_json = db_handle.dump_to_file()
print("json output to db_parser_result")
common_op.save_json_to_file(
handle=page_detail_json,
json_name=".tmp/db_parser_result.json"
)
def test_db_table_inline_parser_md(query, export_child=False):
db_handle = Dump(
dump_id=DB_TABLE_INLINE_ID,
query_handle=query,
export_child_pages=export_child,
dump_type=NotionDump.DUMP_TYPE_DB_TABLE,
db_parser_type=NotionDump.PARSER_TYPE_MD,
)
# 将解析内容存储到文件中;返回内容存储为json文件
page_detail_json = db_handle.dump_to_file()
print("json output to db_parser_result")
common_op.save_json_to_file(
handle=page_detail_json,
json_name=".tmp/db_parser_result.json"
)
if __name__ == '__main__':
query_handle = NotionQuery(token=TOKEN_TEST)
if query_handle is None:
logging.exception("query handle init error")
exit(-1)
# 数据库存储到CSV文件
# test_db_table_inline_parser_csv(query_handle, True)
# 数据库存储到MD文件
test_db_table_inline_parser_md(query_handle, True)
# 数据库存储到字典
# test_db_table_inline_parser_dic(query_handle)