Skip to content

Commit

Permalink
Merge pull request #21 from prius/dev-batch-api
Browse files Browse the repository at this point in the history
Switched to batch leetcode API
  • Loading branch information
fspv authored Oct 26, 2021
2 parents fcd4989 + 643efda commit 98dfdcd
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 200 deletions.
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

0 comments on commit 98dfdcd

Please sign in to comment.