Skip to content

Commit a03477c

Browse files
authored
Merge pull request #27 from xnorpx/dev/list_id
Add list_id to cli to allow to generate deck based on lc list
2 parents e085968 + 00668ea commit a03477c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

generate.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def parse_args() -> argparse.Namespace:
4242
help="Get at most this many problems (decrease if leetcode API times out)",
4343
default=1000,
4444
)
45+
parser.add_argument(
46+
"--list-id",
47+
type=str,
48+
help="Get all questions from a specific list id (https://leetcode.com/list?selectedList=<list_id>",
49+
default="",
50+
)
4551
parser.add_argument(
4652
"--output-file",
4753
type=str,
@@ -103,7 +109,7 @@ async def generate_anki_note(
103109
)
104110

105111

106-
async def generate(start: int, stop: int, page_size: int, output_file: str) -> None:
112+
async def generate(start: int, stop: int, page_size: int, list_id: str, output_file: str) -> None:
107113
"""
108114
Generate an Anki deck
109115
"""
@@ -170,7 +176,7 @@ async def generate(start: int, stop: int, page_size: int, output_file: str) -> N
170176
)
171177
leetcode_deck = genanki.Deck(LEETCODE_ANKI_DECK_ID, Path(output_file).stem)
172178

173-
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData(start, stop, page_size)
179+
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData(start, stop, page_size, list_id)
174180

175181
note_generators: List[Coroutine[Any, Any, LeetcodeNote]] = []
176182

@@ -198,8 +204,8 @@ async def main() -> None:
198204
"""
199205
args = parse_args()
200206

201-
start, stop, page_size, output_file = args.start, args.stop, args.page_size, args.output_file
202-
await generate(start, stop, page_size, output_file)
207+
start, stop, page_size, list_id, output_file = args.start, args.stop, args.page_size, args.list_id, args.output_file
208+
await generate(start, stop, page_size, list_id, output_file)
203209

204210

205211
if __name__ == "__main__":

leetcode_anki/helpers/leetcode.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class LeetcodeData:
8383
names.
8484
"""
8585

86-
def __init__(self, start: int, stop: int, page_size: int = 1000) -> None:
86+
def __init__(self, start: int, stop: int, page_size: int = 1000, list_id: str = "") -> None:
8787
"""
8888
Initialize leetcode API and disk cache for API responses
8989
"""
@@ -102,6 +102,7 @@ def __init__(self, start: int, stop: int, page_size: int = 1000) -> None:
102102
self._start = start
103103
self._stop = stop
104104
self._page_size = page_size
105+
self._list_id = list_id
105106

106107
@cached_property
107108
def _api_instance(self) -> leetcode.api.default_api.DefaultApi:
@@ -140,6 +141,7 @@ def _get_problems_count(self) -> int:
140141
skip=0,
141142
filters=leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput(
142143
tags=[],
144+
list_id=self._list_id
143145
# difficulty="MEDIUM",
144146
# status="NOT_STARTED",
145147
# list_id="7p5x763", # Top Amazon Questions
@@ -193,7 +195,9 @@ def _get_problems_data_page(
193195
category_slug="",
194196
limit=page_size,
195197
skip=offset + page * page_size,
196-
filters=leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput(),
198+
filters=leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput(
199+
list_id=self._list_id
200+
),
197201
),
198202
operation_name="problemsetQuestionList",
199203
)

0 commit comments

Comments
 (0)