Skip to content

Commit e891ad1

Browse files
author
Gareth
authored
Merge pull request #476 from Labelbox/gj/readme-upload
Finalize readme upload
2 parents 1ba386b + aee1906 commit e891ad1

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

examples/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11

2-
3-
4-
5-
convert:
6-
python scripts/tutorials.py --config-path 'scripts/config.json'
2+
upload:
3+
python scripts/upload_documentation.py --config-path 'scripts/config.json'

examples/scripts/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"dir": "basics",
4-
"title": "Basics",
4+
"title": "Getting started",
55
"order": 0
66
},
77
{
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"dir": "annotation_import",
19-
"title": "Annotation import",
19+
"title": "Annotation import (Ground Truth & MAL)",
2020
"order": 3
2121
},
2222
{

examples/scripts/tutorials.py renamed to examples/scripts/upload_documentation.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616

1717
def upload_doc(path, section):
18-
title = path.split('/')[-1].replace(".ipynb", '').capitalize().replace('_', ' ')
18+
title = path.split('/')[-1].replace(".ipynb",
19+
'').capitalize().replace('_', ' ')
1920

2021
with open(path) as fb:
2122
nb = nbformat.reads(json.dumps(json.load(fb)), as_version=4)
@@ -27,11 +28,16 @@ def upload_doc(path, section):
2728
body, resources = exporter.from_notebook_node(nb)
2829

2930
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
3541
}
3642

3743
headers = {
@@ -52,7 +58,7 @@ def make_sections(sections):
5258
payload = {
5359
"hidden": True,
5460
"order": section['order'],
55-
"title": section['title'].replace(' ', '-') + '-nb-section',
61+
"title": 'section-' + section['dir'] + '-notebooks',
5662
"category": CATEGORY_ID
5763
}
5864
headers = {
@@ -73,29 +79,29 @@ def make_sections(sections):
7379

7480

7581
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)
8488
resp.raise_for_status()
8589

8690

8791
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}
9293

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)
9498
docs = response.json()
9599
for doc in docs:
96100
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)
99105

100106

101107
@click.command()

0 commit comments

Comments
 (0)