Skip to content

Commit 077999f

Browse files
committed
Add list_id to cli to allow to generate deck based on lc list
1 parent 191aedf commit 077999f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

generate.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def parse_args() -> argparse.Namespace:
4141
help="Get at most this many problems (decrease if leetcode API times out)",
4242
default=1000,
4343
)
44+
parser.add_argument(
45+
"--list-id",
46+
type=str,
47+
help="Get all questions from a specific list id (https://leetcode.com/list?selectedList=<list_id>",
48+
default="",
49+
)
4450

4551
args = parser.parse_args()
4652

@@ -96,7 +102,7 @@ async def generate_anki_note(
96102
)
97103

98104

99-
async def generate(start: int, stop: int, page_size: int) -> None:
105+
async def generate(start: int, stop: int, page_size: int, list_id: str) -> None:
100106
"""
101107
Generate an Anki deck
102108
"""
@@ -163,7 +169,7 @@ async def generate(start: int, stop: int, page_size: int) -> None:
163169
)
164170
leetcode_deck = genanki.Deck(LEETCODE_ANKI_DECK_ID, "leetcode")
165171

166-
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData(start, stop, page_size)
172+
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData(start, stop, page_size, list_id)
167173

168174
note_generators: List[Coroutine[Any, Any, LeetcodeNote]] = []
169175

@@ -191,8 +197,8 @@ async def main() -> None:
191197
"""
192198
args = parse_args()
193199

194-
start, stop, page_size = args.start, args.stop, args.page_size
195-
await generate(start, stop, page_size)
200+
start, stop, page_size, list_id = args.start, args.stop, args.page_size, args.list_id
201+
await generate(start, stop, page_size, list_id)
196202

197203

198204
if __name__ == "__main__":

leetcode_anki/helpers/leetcode.py

Lines changed: 6 additions & 2 deletions
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)