Skip to content

Commit 059fb5a

Browse files
committed
move template parameter into notebook generator itself
1 parent 1aa8725 commit 059fb5a

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
*.ipynb
2+
.ipynb_checkpoints
13
*.bundle.*
24
lib/
35
node_modules/

jupyterlab_leetcode/handlers/leetcode_handler.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import os
32
from typing import Any, Mapping, cast, overload
43

54
import tornado
@@ -356,18 +355,7 @@ async def post(self):
356355

357356
notebook_generator = self.settings.get("notebook_generator")
358357
if not notebook_generator:
359-
template_path = os.path.join(
360-
os.path.dirname(os.path.realpath(__file__)),
361-
"..",
362-
"utils",
363-
"notebook.template.json",
364-
)
365-
if not os.path.exists(template_path):
366-
self.set_status(500)
367-
self.finish({"message": "Notebook template not found"})
368-
return
369-
370-
notebook_generator = NotebookGenerator(template_path)
358+
notebook_generator = NotebookGenerator()
371359
self.settings.update(notebook_generator=notebook_generator)
372360

373361
file_path = notebook_generator.generate(question)

jupyterlab_leetcode/utils/notebook_generator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
Use LeetCode's GraphQL API to generate question notebook
3-
"""
4-
51
import json
62
import os
73
import re
@@ -16,7 +12,12 @@ def get_folder_for(qid: int, interval: int) -> str:
1612

1713

1814
class NotebookGenerator:
19-
def __init__(self, template_path):
15+
def __init__(self):
16+
template_path = os.path.join(
17+
os.path.dirname(os.path.realpath(__file__)),
18+
"notebook.template.json",
19+
)
20+
2021
with open(template_path, "rt") as f:
2122
self.template = json.load(f)
2223

0 commit comments

Comments
 (0)