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
3D Printed Flip Clock Design and Code

Smart Flip Clock 3D printed smart clock that puts a new twist on old technology. Making The Smart Flip Clock The first thing that must be done for thi

Thomas 105 Oct 17, 2022
A lightweight Python module to interact with the Mitre Att&ck Enterprise dataset.

enterpriseattack - Mitre's Enterprise Att&ck A lightweight Python module to interact with the Mitre Att&ck Enterprise dataset. Built to be used in pro

xakepnz 7 Jan 01, 2023
It converts ING BANK account historic into a csv file you can import in HomeBank application.

ing2homebank It converts your ING Bank account historic csv file into another csv file you can import in HomeBank application

1 Feb 14, 2022
This repository contains code for building education startup.

Learning Management System Overview It's the code for EssayBrain, a tool for teacher that automatically grades and validates essays. In order to valid

Shyam Das Shrestha 1 Nov 21, 2021
An electron application to check battery of bluetooth devices connected to linux devices.

bluetooth-battery-electron An electron application to check battery of bluetooth devices connected to linux devices. This project provides an electron

Vasu Sharma 15 Dec 03, 2022
Tugas kelompok Struktur Data

Binary-Tree Tugas kelompok Struktur Data Silahkan jika ingin mengubah tipe data pada operasi binary tree *Boleh juga semua program kelompok bisa disat

Usmar manalu 2 Nov 28, 2022
Minimalist BERT implementation assignment for CS11-747

minbert Assignment by Zhengbao Jiang, Shuyan Zhou, and Ritam Dutt This is an exercise in developing a minimalist version of BERT, part of Carnegie Mel

Graham Neubig 51 Jan 03, 2023
Open-source library for analyzing the results produced by ABINIT

Package Continuous Integration Documentation About AbiPy is a python library to analyze the results produced by Abinit, an open-source program for the

ABINIT 91 Dec 09, 2022
ERPNext Easy Letterhead

ERPNext Easy Letterhead Intro Quality letterheads are a problem for non-technical users. So we've built (really hacked together) a slightly easier sol

Bantoo 3 Jan 02, 2023
Simple calculator made in python

calculator Uma alculadora simples feita em python CMD, PowerShell, Bash ✔️ Início 💻 apt-get update apt-get upgrade -y apt-get install python git git

Spyware 8 Dec 28, 2021
A Python program that generates a maze that solves itself using DFS

Maze Generator And Solver Program Purpose: Generates a maze that then solves itself Language: Python and Pygame Algorithm: Randomized DFS / Floodfill

Joshua Liu 1 Jul 25, 2022
Скрипт позволяет заводить задачи в Панель мониторинга YouTrack на основе парсинга сайта safe-surf.ru

Скрипт позволяет заводить задачи в Панель мониторинга YouTrack на основе парсинга сайта safe-surf.ru

Bad_karma 3 Feb 12, 2022
Fisherman is a free open source fishing bot written in python.

Fisherman is a free open source fishing bot written in python.

Pure | Cody 33 Jan 29, 2022
使用clash核心,对服务器进行Netflix解锁批量测试。

注意事项 测速及解锁测试仅供参考,不代表实际使用情况,由于网络情况变化、Netflix封锁及ip更换,测速具有时效性 本项目使用 Python 编写,使用前请完成环境安装 首次运行前请安装pip及相关依赖,也可使用 pip install -r requirements.txt 命令自行安装 Net

11 Dec 07, 2022
Team collaborative evaluation tracker.

Team collaborative evaluation tracker.

2 Dec 19, 2021
Repo to store back end infrastructure for Message in a Bottle

Message in a Bottle Backend API RESTful API for Message in a Bottle frontend application consumption. About The Project • Tools Used • Local Set Up •

4 Dec 05, 2021
AIST++ API This repo contains starter code for using the AIST++ dataset.

Explainability for Vision Transformers (in PyTorch) This repository implements methods for explainability in Vision Transformers

Google 260 Dec 30, 2022
Jarvis Python BOT acts like Google-assistance

Jarvis-Python-BOT Jarvis Python BOT acts like Google-assistance Setup Add Mail ID (Gmail) in the file at line no 82.

Ishan Jogalekar 1 Jan 08, 2022
A simple Programming Language

R.S.O.C. A custom built programming language About The Project R.S.O.C. is a custom built programming language very similar to a low-level 8085 progra

Ravi Maurya 17 Sep 13, 2022
CPLib is the abbreviation of Competitive Programming Library.

CPLib CPLib is the abbreviation of Competitive Programming Library. It aims to be a general template and optimization library for competitive programm

12 Oct 16, 2021