Anki cards generator for Leetcode

Overview

Leetcode Anki card generator

Summary

By running this script you'll be able to generate Anki cards with all the leetcode problems.

I personally use it to track my grinding progress.

ezgif-7-03b29041a91e

Installation

First initialize and activate python virtualenv somewhere

virtualenv -p python3 leetcode-anki
. leetcode-anki/bin/activate

Then initialize necessary environment variables. You can get the values directly from your browser

export LEETCODE_CSRF_TOKEN="xxx"
export LEETCODE_SESSION_ID="yyy"

And then run

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.

Comments
  • Add frequency

    Add frequency

    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!

    opened by gh4n 7
  • Generation problem

    Generation problem

    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

    bug good first issue 
    opened by malish8632 6
  • Any way to order the problems?

    Any way to order the problems?

    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?

    opened by zkghost 3
  • Cards are generated with

    Cards are generated with "No content" for some leetcode problems

    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:

    • 2339
    • 2340
    • 2345
    • 2346
    • 2355
    • 2356
    • 2361
    • 2362
    • ...
    opened by lzx404243 2
  • Investigate a possibility to issue batch requests to leetcode

    Investigate a possibility to issue batch requests to leetcode

    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.

    opened by prius 1
  • Fixed for latest leetcode-api changes

    Fixed for latest leetcode-api changes

    Seems your latest changes to the leetcode-api broke the leetcode-anki generation.

    Also had another issue where I didn't get any content from leetcode I think which broke the Anki-generation (since the return was None and not a str.

    Fixed here.

    Let me know what you think.

    Thanks for this package!!

    opened by klintan 1
  • Tests are failing

    Tests are failing

        @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

    opened by prius 0
  • Add option to limit batch requests to Leetcode API

    Add option to limit batch requests to Leetcode API

    Leetcode responses got too large. As a result users are experiencing problem with running the script, because leetcode API fails to return such big results. This diff adds an ability to limit number of problems, downloaded in parallel and limits it to 1000 problems by default.

    opened by prius 0
  • Switched to batch leetcode API

    Switched to batch leetcode API

    With the new batch leetcode API, the generation is now down from 80 minutes to 4 minutes. Also, no longer cache is needed because it is relatively cheap to fetch all the problems from leetcode.

    opened by prius 0
  • Travis CI configuration and Async build

    Travis CI configuration and Async build

    • Added Travis CI configuration, so the package is now built automatically on commit
    • Made the code async so cached cards will be generated faster
    • Switched to PyPi package version
    opened by prius 0
  • How to add solutions?

    How to add solutions?

    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?

    opened by raakasf 2
  • 1 card is missing during deck generation

    1 card is missing during deck generation

    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                                                                                                      
    
    opened by prius 1
  • Sort field doesn't work

    Sort field doesn't work

    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.

    opened by prius 0
Releases(refs/pull/32/merge-1655064977)
Owner
Pavel Safronov
Pavel Safronov
Anki Cards for the HSK vocabulary Chinese-German

Anki-HanyuShuipingKaoshi Anki Cards for the HSK vocabulary Chinese-German Das Deck baut auf folgenden Quellen auf: China Endecken Wortschatz von wohok

null 1 Jan 7, 2022
A free and open-source chess improvement app that combines the power of Lichess and Anki.

A free and open-source chess improvement app that combines the power of Lichess and Anki. Chessli Project Activity & Issue Tracking PyPI Build & Healt

null 93 Nov 23, 2022
Anki for desktop computers

Anki This repo contains the source code for the computer version of Anki. If you'd like to try development builds of Anki but don't feel comfortable b

Ankitects 12.9k Jan 9, 2023
Simple card retirement plugin for Anki

Anki Retirement Addon Allow users to suspend, tag, delete, or move cards that reach a specific retirement interval Supports Anki version 2.1.45 Licens

null 3 Dec 23, 2022
Anki Addon idea by gbrl.sc to see previous ratings of a card in the reviewer

Card History At A Glance Stop having to press card browser and ctrl+i for every card and then WINCING to see it's history of reviews FEATURES Visualiz

Jerry Zhou 11 Dec 19, 2022
A tool converting rpk (记乎) to apkg (Anki Package)

RpkConverter This tool is used to convert rpk file to Anki apkg. 如果遇到任何问题,请发起issue,并描述情况。如果转换rpk出现问题,请将文件发到邮箱 ssqyang [AT] outlook.com,我会debug并修复问题。 下

null 9 Nov 1, 2021
A hackers attempt at an MVP anki plugin

my anki plugin if you have found this by accident, you should probably run away this is nothing more than a hackers attempt at an MVP anki plugin I re

Chris Hall 1 Nov 2, 2021
A Python script to convert your favorite TV series into an Anki deck.

Ankiniser A Python3.8 script to convert your favorite TV series into an Anki deck. How to install? Download the script with git or download it manualy

null 37 Nov 3, 2022
200 LeetCode problems

LeetCode I classify 200 leetcode problems into some categories and upload my code to who concern WEEK 1 # Title Difficulty Array 15 3Sum Medium 1324 P

Hoang Cao Bao 108 Dec 8, 2022
A collection of some leetcode challenges in python and JavaScript

Python and Javascript Coding Challenges Some leetcode questions I'm currently working on to open up my mind to better ways of problem solving. Impleme

Ted Ngeene 1 Dec 20, 2021
Mnemosyne: efficient learning with powerful digital flash-cards.

Mnemosyne: Optimized Flashcards and Research Project Mnemosyne is: a free, open-source, spaced-repetition flashcard program that helps you learn as ef

null 359 Dec 24, 2022
🎴 LearnQuick is a flashcard application that you can study with decks and cards.

?? LearnQuick is a flashcard application that you can study with decks and cards. The main function of the application is to show the front sides of the created cards to the user and ask them to guess the back of the card. As a result of self-assessment of user's ability to guess the back sides of the displayed cards, the cards that user weak against are shown more often, and the cards that user strong against are shown less frequently.

Mehmet Güdük 7 Aug 21, 2022
Easily Generate Revolut Business Cards

RevBusinessCardGen Easily Generate Revolut Business Cards Prerequisites Before you begin, ensure you have met the following requirements: You have ins

Younes™ 35 Dec 14, 2022
A Lego Mindstorm robot for dealing out cards based on a birds-eye view of a poker table and given ArUco fiducial tags.

A Lego Mindstorm robot for dealing out cards based on a birds-eye view of a poker table and given ArUco fiducial tags.

null 4 Dec 6, 2021
Automatically deletes Capital One Eno virtual cards for when you've made a couple too many.

eno-delete Automatically deletes Capital One Eno virtual cards for when you've made a couple too many. Warning: Program will delete ALL virtual cards

h3x 3 Sep 29, 2022
Build Xmas cards with user inputs

Automatically build Xmas cards with user inputs

Anand 9 Jan 25, 2022
A tool to guide you for team selection based on mana and ruleset using your owned cards.

Splinterlands_Teams_Guide A tool to guide you for team selection based on mana and ruleset using your owned cards. Built With This project is built wi

Ruzaini Subri 3 Jul 30, 2022
A small script I made that takes any standard Decklist of magic the gathering cards and pulls all card images from scryfall at once!

A small script I made that takes any standard Decklist of magic the gathering cards and pulls all card images from scryfall at once!

null 15 Aug 26, 2022
Random Turkish name generator with realistic probabilities.

trnames Random Turkish name generator with realistic probabilities. Based on Trey Hunner's names package. Installation The package can be installed us

Kaan Öztürk 20 Jan 2, 2023