-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpynotion.py
44 lines (38 loc) · 1.07 KB
/
pynotion.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
import argparse
from notionpython import NotionPython
RUN = "run"
CLEAN = "clean"
def init() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="pynotion",
usage="%(prog)s [COMMAND]",
description="Executes the code in the notion page described in the environment variables.",
)
parser.add_argument(
"-v", "--version", action="version", version=f"{parser.prog} version 0.0.1"
)
parser.add_argument(
"-t", "--token", dest="token", required=True
)
parser.add_argument(
"-p", "--page", dest="page_id", required=True
)
parser.add_argument(
"-c",
"--command",
dest="action",
default=RUN,
choices=[RUN, CLEAN],
)
return parser
def main() -> None:
parser = init()
args = parser.parse_args()
action = args.action
token = args.token
page_id = args.page_id
notion = NotionPython(token, page_id)
execute_action = {RUN: notion.eval_code, CLEAN: notion.clean_page}
execute_action[action]()
if __name__ == "__main__":
main()