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

    [email protected] [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
Simple rofi script to choose player for playerctl to execute its command

rofi-playerctl-switcher simple rofi script to choose player for playerctl to execute its command Usage copy playerSwitch.py and playerctl.sh to ~/.con

2 Jan 03, 2022
Inacap - Programa para pasar las notas de inacap a una hoja de cálculo rápidamente.

Inacap Programa en python para obtener varios datos académicos desde inacap y subirlos directamente a una hoja de cálculo. Cómo funciona Primero que n

Gabriel Barrientos 0 Jul 28, 2022
Python module for creating the circuit simulation definitions for Elmer FEM

elmer_circuitbuilder Python module for creating the circuit simulation definitions for Elmer FEM. The circuit definitions enable easy setup of coils (

5 Oct 03, 2022
A place where the most basic, basic of python coding exists

python-basics A place where the most basic, basic of python coding exists As you can see, there are four folders and the best order to read is: appeti

Chuqin 2 Oct 05, 2022
2021华为软件精英挑战赛 程序输出分析器

AutoGrader 0.2.0更新:加入资源分配溢出检测,如果发生资源溢出会输出溢出发生的位置。 如果通过检测,会显示通过符号 如果没有通过检测,会显示警告,并输出溢出发生的位置和操作

54 Aug 14, 2022
Just another sentiment wrapper.

sentimany Just a simple sentiment tool. It just grabs a set of pre-made sentiment models that you can quickly use to attach sentiment scores to text.

vincent d warmerdam 15 Dec 27, 2022
A simple project which is a ecm to found a good way to provide a path to img_dir in gooey

ECM to find a good way for img_dir Path in Gooey This code is just an ECM to find a good way to indicate a path of image in image_dir variable. We loo

Jean-Emmanuel Longueville 1 Oct 25, 2021
Extremely unfinished animation toolset for Blender 3.

AbraTools Alpha IMPORTANT: Code is a mess. Be careful using it in production. Bug reports, feature requests and PRs are appreciated. Download AbraTool

Abra 15 Dec 17, 2022
Create N Share is a No Code solution which gives users the ability to create any type of feature rich survey forms with ease.

create n share Note : The Project Scaffold will be pushed soon. Create N Share is a No Code solution which gives users the ability to create any type

Chiraag Kakar 11 Dec 03, 2022
Data Applications Project

DBMS project- Hotel Franchise Data and application project By TEAM Kurukunda Bhargavi Pamulapati Pallavi Greeshma Amaraneni What is this project about

Greeshma 1 Nov 28, 2021
Utility functions for working with data from Nix in Python

Pynixutil - Utility functions for working with data from Nix in Python Examples Base32 encoding/decoding import pynixutil input = "v5sv61sszx301i0x6x

Tweag 11 Dec 16, 2022
Some shitty programs just to brush up on my understanding of binary conversions.

Binary Converters Some shitty programs just to brush up on my understanding of binary conversions. Supported conversions formats = "unsigned-binary" |

Tim 2 Jan 09, 2022
0xFalcon - 0xFalcon Tool For Python

0xFalcone Installation Install 0xFalcone Tool: apt install git git clone https:/

Alharb7 6 Sep 24, 2022
A smart personal companion and health assistant.

Steps to Install : Clone the repository Go to ResQ-Sources Execute ResQ-Lite.py --: Manual Controls : DanceRobot.py --: You can call functions like fo

Tuhinadri Banerjee 1 May 25, 2022
A fast Python in-process signal/event dispatching system.

Blinker Blinker provides a fast dispatching system that allows any number of interested parties to subscribe to events, or "signals". Signal receivers

jason kirtland 1.4k Dec 31, 2022
Hartree-Fock Workshop for the Han-sur-Lesse Winterschool of 2021

Hartree-Fock course for the Han-sur-Lesse Winterschool of 2021 Requirements For going through these exercises, please install the Anaconda suite. Next

Ivo Filot 2 Nov 16, 2022
The purpose is to have a fairly simple python assignment that introduces the basic features and tools of python

This repository contains the code for the python introduction lab. The purpose is to have a fairly simple python assignment that introduces the basic

1 Jan 24, 2022
Source for the Fedora Silverblue and Kinoite variants.

Source for the Fedora Silverblue and Kinoite variants.

Fedora Kinoite 7 Aug 20, 2022
Push Prometheus metrics to VictoriaMetrics or other exporters

Push metrics from your periodic long-running jobs to existing Prometheus/VictoriaMetrics monitoring system.

olegm 14 Nov 04, 2022