Skip to content

Add list_id to cli to allow to generate deck based on lc list #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def parse_args() -> argparse.Namespace:
help="Get at most this many problems (decrease if leetcode API times out)",
default=1000,
)
parser.add_argument(
"--list-id",
type=str,
help="Get all questions from a specific list id (https://leetcode.com/list?selectedList=<list_id>",
default="",
)
parser.add_argument(
"--output-file",
type=str,
Expand Down Expand Up @@ -103,7 +109,7 @@ async def generate_anki_note(
)


async def generate(start: int, stop: int, page_size: int, output_file: str) -> None:
async def generate(start: int, stop: int, page_size: int, list_id: str, output_file: str) -> None:
"""
Generate an Anki deck
"""
Expand Down Expand Up @@ -170,7 +176,7 @@ async def generate(start: int, stop: int, page_size: int, output_file: str) -> N
)
leetcode_deck = genanki.Deck(LEETCODE_ANKI_DECK_ID, Path(output_file).stem)

leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData(start, stop, page_size)
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData(start, stop, page_size, list_id)

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

Expand Down Expand Up @@ -198,8 +204,8 @@ async def main() -> None:
"""
args = parse_args()

start, stop, page_size, output_file = args.start, args.stop, args.page_size, args.output_file
await generate(start, stop, page_size, output_file)
start, stop, page_size, list_id, output_file = args.start, args.stop, args.page_size, args.list_id, args.output_file
await generate(start, stop, page_size, list_id, output_file)


if __name__ == "__main__":
Expand Down
8 changes: 6 additions & 2 deletions leetcode_anki/helpers/leetcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class LeetcodeData:
names.
"""

def __init__(self, start: int, stop: int, page_size: int = 1000) -> None:
def __init__(self, start: int, stop: int, page_size: int = 1000, list_id: str = "") -> None:
"""
Initialize leetcode API and disk cache for API responses
"""
Expand All @@ -102,6 +102,7 @@ def __init__(self, start: int, stop: int, page_size: int = 1000) -> None:
self._start = start
self._stop = stop
self._page_size = page_size
self._list_id = list_id

@cached_property
def _api_instance(self) -> leetcode.api.default_api.DefaultApi:
Expand Down Expand Up @@ -140,6 +141,7 @@ def _get_problems_count(self) -> int:
skip=0,
filters=leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput(
tags=[],
list_id=self._list_id
# difficulty="MEDIUM",
# status="NOT_STARTED",
# list_id="7p5x763", # Top Amazon Questions
Expand Down Expand Up @@ -193,7 +195,9 @@ def _get_problems_data_page(
category_slug="",
limit=page_size,
skip=offset + page * page_size,
filters=leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput(),
filters=leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput(
list_id=self._list_id
),
),
operation_name="problemsetQuestionList",
)
Expand Down