-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpages.py
34 lines (26 loc) · 910 Bytes
/
pages.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
from growi import Growi
import os
import re
import json
import webbrowser
import urllib.parse
import argparse
url=os.environ['GROWI_URL']
access_token = os.environ['GROWI_ACCESS_TOKEN']
g = Growi(url,access_token)
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('file_path', help='Local file path of your markdown document')
parser.add_argument('-b', '--browse', action='store_true', help='Open browser')
parser.add_argument('-u', '--update', action='store_true', help='Update page')
args = parser.parse_args()
path = re.sub('.md$','','/'+args.file_path)
if args.browse:
webbrowser.open_new(urllib.parse.quote(url+path, safe=':/'))
elif args.update:
with open(args.file_path.strip()) as f:
body = f.read()
g.pages_create(path,body)
g.pages_update(path,body)
else:
print(g.pages_get(path))
print(json.loads(g.pages_get(path))["ok"])