Skip to content

Switched to batch leetcode API #21

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
Oct 26, 2021
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
5 changes: 5 additions & 0 deletions .pyre_configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"source_directories": [
"."
]
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ make generate
```

You'll get `leetcode.apkg` file, which you can import directly to your anki app.

There also will be a `cache` directory created for the cached data about the problems. If you want to fetch more up to date information about the existing problems, delete this dir. Just keep in mind, it'll take a while to re-download the data about all the problems.
20 changes: 9 additions & 11 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ async def generate_anki_note(
leetcode_data: leetcode_anki.helpers.leetcode.LeetcodeData,
leetcode_model: genanki.Model,
leetcode_task_handle: str,
leetcode_task_title: str,
topic: str,
) -> LeetcodeNote:
"""
Generate a single Anki flashcard
Expand All @@ -68,8 +66,8 @@ async def generate_anki_note(
fields=[
leetcode_task_handle,
str(await leetcode_data.problem_id(leetcode_task_handle)),
leetcode_task_title,
topic,
str(await leetcode_data.title(leetcode_task_handle)),
str(await leetcode_data.category(leetcode_task_handle)),
await leetcode_data.description(leetcode_task_handle),
await leetcode_data.difficulty(leetcode_task_handle),
"yes" if await leetcode_data.paid(leetcode_task_handle) else "no",
Expand Down Expand Up @@ -158,24 +156,24 @@ async def generate(start: int, stop: int) -> None:
],
)
leetcode_deck = genanki.Deck(LEETCODE_ANKI_DECK_ID, "leetcode")
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData()

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

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

for topic, leetcode_task_title, leetcode_task_handle in list(
leetcode_anki.helpers.leetcode.get_leetcode_task_handles()
)[start:stop]:
task_handles = await leetcode_data.all_problems_handles()

logging.info("Generating flashcards")
for leetcode_task_handle in task_handles:
note_generators.append(
generate_anki_note(
leetcode_data,
leetcode_model,
leetcode_task_handle,
leetcode_task_title,
topic,
)
)

for leetcode_note in tqdm(note_generators):
for leetcode_note in tqdm(note_generators, unit="flashcard"):
leetcode_deck.add_note(await leetcode_note)

genanki.Package(leetcode_deck).write_to_file(OUTPUT_FILE)
Expand Down
Loading