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
How to access and display MyEnergi data

MyEnergi-Python-Example How to access and display MyEnergi data Windows PC Install a version of Python typically 3.10 The Python code here needs addit

G6EJD 8 Nov 28, 2022
Coderslab Workshop Projects

Workshop Coderslab workshop projects that include: Guessing Game Lotto simulator Guessing Game vol.2 Guessing Game vol.3 Dice 2001 Game Technologies P

Szymon Połczyński 1 Nov 06, 2021
Async timeit - Async version of python's timeit

Async Timeit Replica of default python timeit module with small changes to allow

Raghava G Dhanya 3 Apr 13, 2022
Example platform plugin that fixes fentry calls in Binja

Example Binja Platform Plugin This is an example Binja platform plugin which fixes up linux kernel module calls to __fentry__. __fentry__ is the linux

_yrp 2 Oct 07, 2021
List of short Codeforces problems with a statement of 1000 characters or less. Python script and data files included.

Shortest problems on Codeforces List of Codeforces problems with a short problem statement of 1000 characters or less. Sorted for each rating level. B

32 Dec 24, 2022
A Python package for searching journal publications and researchers

scholarpy A python package for searching journal publications and researchers Free software: MIT license Documentation: https://giswqs.github.io/schol

Qiusheng Wu 8 Mar 12, 2022
msgqywx 使用企业微信的应用消息推送实时信息

msgqywx 使用企业微信的应用消息推送实时信息

Demon Finch 8 Dec 18, 2022
An osu! cheat made in c++ rewritten in python and currently undetected.

megumi-python An osu! cheat made in c++ rewritten in python and currently undetected. Installation Guide Download python 3.9 from https://python.org C

Elaina 2 Nov 18, 2022
🌍💉 Global COVID-19 vaccination data at the regional level.

COVID-19 vaccination data at subnational level. To ensure its officiality, the source data is carefully verified.

sociepy 61 Sep 21, 2022
GWAS summary statistics files QC tool

SSrehab dependencies: python 3.8+ a GNU/Linux with bash v4 or 5. python packages in requirements.txt bcftools (only for prepare_dbSNPs) gz-sort (only

21 Nov 02, 2022
Program to send ROM files to Turbo Everdrive; reverse-engineered and designed to be platform-independent

PCE_TurboEverdrive_USB What is this "TurboEverdrive USB" thing ? For those who have a TurboEverdrive v2.x from krikzz.com, there was originally an opt

David Shadoff 10 Sep 18, 2022
Scitizen - Help scientific research for the benefit of mankind and humanity 🔬

Scitizen - Help scientific research for the benefit of mankind and humanity 🔬 Scitizen has been built from the ground up to give everyone the possibi

Pierre CORBEL 21 Mar 08, 2022
A Python library that helps data scientists to infer causation rather than observing correlation.

A Python library that helps data scientists to infer causation rather than observing correlation.

QuantumBlack Labs 1.7k Jan 04, 2023
Feapder的管道扩展

FEAPDER 管道扩展 简介 此模块为feapder的pipelines扩展,感谢广大开发者对feapder的贡献 随着feapder支持的pipelines越来越多,为减少feapder的体积,特将pipelines提出,使用者可按需安装 管道 PostgreSQL 贡献者:沈瑞祥 联系方式:r

boris 9 Dec 07, 2022
a simple functional programming language compiler written in python

Functional Programming Language A compiler for my small functional language. Written in python with SLY lexer/parser generator library. Requirements p

Ashkan Laei 3 Nov 05, 2021
py-js: python3 objects for max

Simple (and extensible) python3 externals for MaxMSP

Shakeeb Alireza 39 Nov 20, 2022
This is a Fava extension to display a grouped portfolio view in Fava for a set of Beancount accounts.

Fava Portfolio Summary This is a Fava extension to display a grouped portfolio view in Fava for a set of Beancount accounts. It can also calculate MWR

18 Dec 26, 2022
Example of my qtile config using the gruvbox colorscheme.

QTILE config Example of my qtile config using the gruvbox colorscheme. unicodes.py unicodes.py returns a widget.TextBox with a unicode. Currently it c

Imanuel Febie 31 Jan 02, 2023
Pampy: The Pattern Matching for Python you always dreamed of.

Pampy: Pattern Matching for Python Pampy is pretty small (150 lines), reasonably fast, and often makes your code more readable and hence easier to rea

Claudio Santini 3.5k Dec 30, 2022
Attempt at creating organized collection of little handy snippets of code I'm receiving along the way

ChaosCode Attempt at creating organized collection of little handy snippets of code I'm receiving along the way I always considered coding and program

INFU 4 Nov 26, 2022