Skip to content

Commit 00668ea

Browse files
authored
Merge branch 'master' into dev/list_id
2 parents 077999f + e085968 commit 00668ea

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,38 @@ cd leetcode-anki
3333
```
3434

3535
After that initialize and activate python virtualenv somewhere
36+
37+
Linux/MacOS
3638
```
3739
virtualenv -p python leetcode-anki
3840
. leetcode-anki/bin/activate
3941
```
4042

43+
Windows
44+
```
45+
python -m venv leetcode-anki
46+
.\leetcode-anki\Scripts\activate.bat
47+
```
48+
4149
Then initialize session id variable. You can get it directly from your browser (if you're using chrome, cookies can be found here chrome://settings/cookies/detail?site=leetcode.com)
50+
51+
Linux/Macos
4252
```
4353
export LEETCODE_SESSION_ID="yyy"
4454
```
4555

46-
And finally run
56+
Windows
57+
```
58+
set LEETCODE_SESSION_ID="yyy"
59+
```
60+
61+
And finally run for Linux/MacOS
4762
```
4863
make generate
4964
```
65+
Or for Windows
66+
```
67+
python generate.py
68+
```
5069

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

generate.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import argparse
88
import asyncio
99
import logging
10+
from pathlib import Path
1011
from typing import Any, Coroutine, List
1112

1213
# https://github.com/kerrickstaley/genanki
@@ -47,6 +48,12 @@ def parse_args() -> argparse.Namespace:
4748
help="Get all questions from a specific list id (https://leetcode.com/list?selectedList=<list_id>",
4849
default="",
4950
)
51+
parser.add_argument(
52+
"--output-file",
53+
type=str,
54+
help="Output filename",
55+
default=OUTPUT_FILE,
56+
)
5057

5158
args = parser.parse_args()
5259

@@ -102,7 +109,7 @@ async def generate_anki_note(
102109
)
103110

104111

105-
async def generate(start: int, stop: int, page_size: int, list_id: str) -> None:
112+
async def generate(start: int, stop: int, page_size: int, list_id: str, output_file: str) -> None:
106113
"""
107114
Generate an Anki deck
108115
"""
@@ -167,7 +174,7 @@ async def generate(start: int, stop: int, page_size: int, list_id: str) -> None:
167174
},
168175
],
169176
)
170-
leetcode_deck = genanki.Deck(LEETCODE_ANKI_DECK_ID, "leetcode")
177+
leetcode_deck = genanki.Deck(LEETCODE_ANKI_DECK_ID, Path(output_file).stem)
171178

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

@@ -188,7 +195,7 @@ async def generate(start: int, stop: int, page_size: int, list_id: str) -> None:
188195
for leetcode_note in tqdm(note_generators, unit="flashcard"):
189196
leetcode_deck.add_note(await leetcode_note)
190197

191-
genanki.Package(leetcode_deck).write_to_file(OUTPUT_FILE)
198+
genanki.Package(leetcode_deck).write_to_file(output_file)
192199

193200

194201
async def main() -> None:
@@ -197,8 +204,8 @@ async def main() -> None:
197204
"""
198205
args = parse_args()
199206

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)
207+
start, stop, page_size, list_id, output_file = args.start, args.stop, args.page_size, args.list_id, args.output_file
208+
await generate(start, stop, page_size, list_id, output_file)
202209

203210

204211
if __name__ == "__main__":

leetcode_anki/helpers/leetcode.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ async def tags(self, problem_slug: str) -> List[str]:
353353
List of the tags for this problem (string slugs)
354354
"""
355355
data = self._get_problem_data(problem_slug)
356-
return list(map(lambda x: x.slug, data.topic_tags))
356+
tags = list(map(lambda x: x.slug, data.topic_tags))
357+
tags.append(data.difficulty)
358+
return tags
357359

358360
async def freq_bar(self, problem_slug: str) -> float:
359361
"""

0 commit comments

Comments
 (0)