Skip to content

Commit 643efda

Browse files
committed
Fetching problems in batches using new leetcode api
1 parent 0332d55 commit 643efda

File tree

5 files changed

+372
-200
lines changed

5 files changed

+372
-200
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ make generate
3737
```
3838

3939
You'll get `leetcode.apkg` file, which you can import directly to your anki app.
40-
41-
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.

generate.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ async def generate_anki_note(
5757
leetcode_data: leetcode_anki.helpers.leetcode.LeetcodeData,
5858
leetcode_model: genanki.Model,
5959
leetcode_task_handle: str,
60-
leetcode_task_title: str,
61-
topic: str,
6260
) -> LeetcodeNote:
6361
"""
6462
Generate a single Anki flashcard
@@ -68,8 +66,8 @@ async def generate_anki_note(
6866
fields=[
6967
leetcode_task_handle,
7068
str(await leetcode_data.problem_id(leetcode_task_handle)),
71-
leetcode_task_title,
72-
topic,
69+
str(await leetcode_data.title(leetcode_task_handle)),
70+
str(await leetcode_data.category(leetcode_task_handle)),
7371
await leetcode_data.description(leetcode_task_handle),
7472
await leetcode_data.difficulty(leetcode_task_handle),
7573
"yes" if await leetcode_data.paid(leetcode_task_handle) else "no",
@@ -158,24 +156,24 @@ async def generate(start: int, stop: int) -> None:
158156
],
159157
)
160158
leetcode_deck = genanki.Deck(LEETCODE_ANKI_DECK_ID, "leetcode")
161-
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData()
159+
160+
leetcode_data = leetcode_anki.helpers.leetcode.LeetcodeData(start, stop)
162161

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

165-
for topic, leetcode_task_title, leetcode_task_handle in list(
166-
leetcode_anki.helpers.leetcode.get_leetcode_task_handles()
167-
)[start:stop]:
164+
task_handles = await leetcode_data.all_problems_handles()
165+
166+
logging.info("Generating flashcards")
167+
for leetcode_task_handle in task_handles:
168168
note_generators.append(
169169
generate_anki_note(
170170
leetcode_data,
171171
leetcode_model,
172172
leetcode_task_handle,
173-
leetcode_task_title,
174-
topic,
175173
)
176174
)
177175

178-
for leetcode_note in tqdm(note_generators):
176+
for leetcode_note in tqdm(note_generators, unit="flashcard"):
179177
leetcode_deck.add_note(await leetcode_note)
180178

181179
genanki.Package(leetcode_deck).write_to_file(OUTPUT_FILE)

0 commit comments

Comments
 (0)