Nothing here yet
fspv / leetcode-anki Goto Github PK
View Code? Open in Web Editor NEWAnki cards generator for Leetcode
License: MIT License
Anki cards generator for Leetcode
License: MIT License
Nothing here yet
Hey @prius would it be possible to get the frequency
of a problem as a tag in anki? This would make it a lot easier to prioritise canonical problems.
Thanks I really love this tool!
For a small subset of questions, the generated cards don't capture the question content but instead, have the Content field being No content
.
For instance, problem 2340 has such an issue deterministically, while problem 2341 always shows up fine.
Some Leetcode questions with Content
field being no content
:
Hi @prius, tried to generate and got this error:
test ! "x/Users/user/Downloads/leetcode-anki/leetcode-anki" = "x" || (echo "Need to run inside venv" && exit 1)
pip install -r requirements.txt
Requirement already satisfied: python-leetcode in ./leetcode-anki/lib/python3.9/site-packages (from -r requirements.txt (line 1)) (1.0.6)
Requirement already satisfied: diskcache in ./leetcode-anki/lib/python3.9/site-packages (from -r requirements.txt (line 2)) (5.2.1)
Requirement already satisfied: genanki in ./leetcode-anki/lib/python3.9/site-packages (from -r requirements.txt (line 3)) (0.11.0)
Requirement already satisfied: tqdm in ./leetcode-anki/lib/python3.9/site-packages (from -r requirements.txt (line 4)) (4.62.3)
Requirement already satisfied: certifi in ./leetcode-anki/lib/python3.9/site-packages (from python-leetcode->-r requirements.txt (line 1)) (2021.10.8)
Requirement already satisfied: urllib3>=1.15 in ./leetcode-anki/lib/python3.9/site-packages (from python-leetcode->-r requirements.txt (line 1)) (1.26.7)
Requirement already satisfied: python-dateutil in ./leetcode-anki/lib/python3.9/site-packages (from python-leetcode->-r requirements.txt (line 1)) (2.8.2)
Requirement already satisfied: six>=1.10 in ./leetcode-anki/lib/python3.9/site-packages (from python-leetcode->-r requirements.txt (line 1)) (1.16.0)
Requirement already satisfied: cached-property in ./leetcode-anki/lib/python3.9/site-packages (from genanki->-r requirements.txt (line 3)) (1.5.2)
Requirement already satisfied: pyyaml in ./leetcode-anki/lib/python3.9/site-packages (from genanki->-r requirements.txt (line 3)) (6.0)
Requirement already satisfied: frozendict in ./leetcode-anki/lib/python3.9/site-packages (from genanki->-r requirements.txt (line 3)) (2.0.6)
Requirement already satisfied: pystache in ./leetcode-anki/lib/python3.9/site-packages (from genanki->-r requirements.txt (line 3)) (0.5.0)
python3 generate.py
Traceback (most recent call last):
File "/Users/user/Downloads/leetcode-anki/generate.py", line 14, in
import genanki # type: ignore
File "/Users/user/Downloads/leetcode-anki/leetcode-anki/lib/python3.9/site-packages/genanki/init.py", line 6, in
from .model import Model
File "/Users/user/Downloads/leetcode-anki/leetcode-anki/lib/python3.9/site-packages/genanki/model.py", line 3, in
import pystache
File "/Users/user/Downloads/leetcode-anki/leetcode-anki/lib/python3.9/site-packages/pystache/init.py", line 2, in
from init import *
ModuleNotFoundError: No module named 'init'
make: *** [generate] Error 1
Now when it works, it's time to make it look nice as well.
So we need to split the script into files and make a nice CLI for that.
I love this, but I expected it to fetch solution information/strategies and actual solution code in various languages.
Is there an easy way to edit this to get a deck with cards with the problems on the front and tons of solution info on the back? (Maybe with fields for solution/s and strategy/ies descriptions and solution lang fields like python, java, typescript, etc,. and maybe even including a field about which lang is fastest)
I am looking for a way to use Anki to memorize all the problems AND their solution/s, not just what the problems are. I feel this would be a quicker way to learn. Any ideas? Could you point me in the right direction?
When a new release is created via GitHub actions, the leetcode.apkg
file is visible in the assets and has a size, but its content is missing (GitHub returns 404 when you try to download it).
An example: https://github.com/prius/leetcode-anki/releases/tag/refs%2Fheads%2Fmaster-1635295155
I tried to fork the repo and create a new release myself but ended up with the same issue: https://github.com/dropsonic/leetcode-anki/releases/tag/refs%2Fheads%2Fmaster-1676754546
The Build Anki deck
workflow doesn't show any errors. The "Upload release asset" step succeeded without any errors.
It is possible to issue batch requests to the leetcode API. The current method is super slow. There are graphql queries that allow you to fetch many problems at once. But they should be implemented in the python-leetcode
library first.
Might be useful
Leetcode return tehre are 2052 cards, but we get 2051 in the end. It is either a bug with the way we calculate pages and offsets, or leetcode really returns incorrect number of problems. Have to investigate
spv@laptop [venv:leetcode-anki] leetcode-anki $ time ipython3 --pdb -- generate.py
INFO:root:Fetching 2052 problems 50 per page
100%|████████████████████████████████████████████████████████████████████████| 2100/2100 [04:37<00:00, 7.58problem/s]
INFO:root:Generating flashcards
100%|███████████████████████████████████████████████████████████████████| 2051/2051 [00:00<00:00, 28815.78flashcard/s]
real 4m41.243s
user 0m3.262s
sys 0m0.440s
I've found the most helpful thing for me so far is using curated/organized lists, like this one.
I started manually making cards and it is a pain, so your tool seems great! But I am concerned if Anki is just going to randomly throw all 25XX problems at me, it won't be as effective.
Is there any way (via this or in Anki) to encourage/constrain the cards or their ordering?
I set the sort field to 3 digits string at the moment: https://github.com/prius/leetcode-anki/blob/master/generate.py#L298
But the sorting is still incorrect.
For example, there are 15 cards for which sorting by the sort field gives the following order:
012
010
025
011
023
006
002
035
008
033
036
037
037
011
048
So effective there is no sorting.
I guess I need to look at Anki's source code to understand how it uses this field.
Hello, I'm on a Mac running Python 3.11.1 and receiving an error when running the make generate
build script.
Below is an output from CLI
python3 generate.py /private/tmp/test/leetcode-anki/generate.py:215: DeprecationWarning: There is no current event loop loop: asyncio.events.AbstractEventLoop = asyncio.get_event_loop() Traceback (most recent call last): File "/private/tmp/test/leetcode-anki/generate.py", line 216, in <module> loop.run_until_complete(main()) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/generate.py", line 211, in main await generate(start, stop, page_size, list_id, output_file) File "/private/tmp/test/leetcode-anki/generate.py", line 184, in generate task_handles = await leetcode_data.all_problems_handles() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 274, in all_problems_handles return list(self._cache.keys()) ^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/functools.py", line 1001, in __get__ val = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 143, in _cache problems = self._get_problems_data() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 240, in _get_problems_data problem_count = self._get_problems_count() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 76, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 148, in _get_problems_count api_instance = self._api_instance ^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/functools.py", line 1001, in __get__ val = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 134, in _api_instance return _get_leetcode_api_client() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode_anki/helpers/leetcode.py", line 38, in _get_leetcode_api_client csrf_token = leetcode.auth.get_csrf_cookie(session_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode-anki/lib/python3.11/site-packages/leetcode/auth.py", line 12, in get_csrf_cookie return response.cookies["csrftoken"] ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode-anki/lib/python3.11/site-packages/requests/cookies.py", line 334, in __getitem__ return self._find_no_duplicates(name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/test/leetcode-anki/leetcode-anki/lib/python3.11/site-packages/requests/cookies.py", line 413, in _find_no_duplicates raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}") KeyError: "name='csrftoken', domain=None, path=None" make: *** [generate] Error 1
Any suggestions on how to fix this? I have followed the README steps to a T.
This repo is really awesome and just what I was doing for myself.
I just have a question about adding my own solutions to the "back" card. I managed to add the field but it's not the back. And I don't see the discuss and solutions card.. could you help me with this?
@pytest.mark.asyncio
@mock.patch(
"leetcode_anki.helpers.leetcode.LeetcodeData._get_problems_data",
mock.Mock(return_value=[QUESTION_DETAIL]),
)
async def test_tags(self) -> None:
self._leetcode_data._cache["test"] = QUESTION_DETAIL
> assert (await self._leetcode_data.tags("test")) == ["test-tag"]
E AssertionError: assert ['test-tag', 'Hard'] == ['test-tag']
E Left contains one more item: 'Hard'
E Use -v to get more diff
test/helpers/test_leetcode.py:248: AssertionError
This is due to logic change
can you make more documentation on how to actually use this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.