15
15
16
16
17
17
def upload_doc (path , section ):
18
- title = path .split ('/' )[- 1 ].replace (".ipynb" , '' ).capitalize ().replace ('_' , ' ' )
18
+ title = path .split ('/' )[- 1 ].replace (".ipynb" ,
19
+ '' ).capitalize ().replace ('_' , ' ' )
19
20
20
21
with open (path ) as fb :
21
22
nb = nbformat .reads (json .dumps (json .load (fb )), as_version = 4 )
@@ -27,11 +28,16 @@ def upload_doc(path, section):
27
28
body , resources = exporter .from_notebook_node (nb )
28
29
29
30
payload = {
30
- "hidden" : True ,
31
- "title" : f'{ section ["slug" ]} -' + title .replace (' ' , '-' ),
32
- "category" : CATEGORY_ID ,
33
- "parentDoc" : section ['id' ],
34
- "body" : body
31
+ "hidden" :
32
+ True ,
33
+ "title" :
34
+ f'{ section ["slug" ]} -' + title .replace (' ' , '-' ).replace ("(" , '' ),
35
+ "category" :
36
+ CATEGORY_ID ,
37
+ "parentDoc" :
38
+ section ['id' ],
39
+ "body" :
40
+ body
35
41
}
36
42
37
43
headers = {
@@ -52,7 +58,7 @@ def make_sections(sections):
52
58
payload = {
53
59
"hidden" : True ,
54
60
"order" : section ['order' ],
55
- "title" : section [ 'title' ]. replace ( ' ' , '-' ) + '-nb-section ' ,
61
+ "title" : ' section-' + section [ 'dir' ] + '-notebooks ' ,
56
62
"category" : CATEGORY_ID
57
63
}
58
64
headers = {
@@ -73,29 +79,29 @@ def make_sections(sections):
73
79
74
80
75
81
def change_name (slug , title , headers ):
76
- resp = requests .put (
77
- f'{ README_DOC_ENDPOINT } /{ slug } ' ,
78
- json = {
79
- "title" : title ,
80
- "category" : CATEGORY_ID
81
- },
82
- headers = headers
83
- )
82
+ resp = requests .put (f'{ README_DOC_ENDPOINT } /{ slug } ' ,
83
+ json = {
84
+ "title" : title ,
85
+ "category" : CATEGORY_ID
86
+ },
87
+ headers = headers )
84
88
resp .raise_for_status ()
85
89
86
90
87
91
def erase_category_docs (cat_slug ):
88
- headers = {
89
- "Accept" : "application/json" ,
90
- "Authorization" : README_AUTH
91
- }
92
+ headers = {"Accept" : "application/json" , "Authorization" : README_AUTH }
92
93
93
- response = requests .request ("GET" , f'https://dash.readme.com/api/v1/categories/{ cat_slug } /docs' , headers = headers )
94
+ response = requests .request (
95
+ "GET" ,
96
+ f'https://dash.readme.com/api/v1/categories/{ cat_slug } /docs' ,
97
+ headers = headers )
94
98
docs = response .json ()
95
99
for doc in docs :
96
100
for child in doc ["children" ]:
97
- resp = requests .delete (f'{ README_DOC_ENDPOINT } /{ child ["slug" ]} ' , headers = headers )
98
- resp = requests .delete (f'{ README_DOC_ENDPOINT } /{ doc ["slug" ]} ' , headers = headers )
101
+ resp = requests .delete (f'{ README_DOC_ENDPOINT } /{ child ["slug" ]} ' ,
102
+ headers = headers )
103
+ resp = requests .delete (f'{ README_DOC_ENDPOINT } /{ doc ["slug" ]} ' ,
104
+ headers = headers )
99
105
100
106
101
107
@click .command ()
0 commit comments