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
Service for working with open data of the State Duma of the Russian Federation

Сервис для работы с открытыми данными Госдумы РФ Исходные данные из API Госдумы РФ извлекаются с помощью Apache Nifi и приземляются в хранилище Clickh

Aleksandr Sergeenko 2 Feb 14, 2022
Import some key/value data to Prometheus custom-built Node Exporter in Python

About the app In one particilar project, i had to import some key/value data to Prometheus. So i have decided to create my custom-built Node Exporter

Hamid Hosseinzadeh 1 May 19, 2022
Displays Christmas-themed ASCII art

Christmas Color Scripts Displays Christmas-themed ASCII art. This was mainly inspired by DistroTube's Shell Color Scripts Screenshots ASCII Shadow Tex

1 Aug 09, 2022
Educational Repo. Used whilst learning Flask.

flask_python Educational Repo. Used whilst learning Flask. The below instructions will be required whilst establishing as new project. Install Flask (

Jordan 2 Oct 15, 2021
Contain the customization I made for my Linux rice.

dotfiles Contain the customization I made for my Linux rice. Credit and Respect Polybar Autohide Fulltime Rofi by adi1090x (only include my personal r

sora 3 Apr 04, 2022
Exploring basic lambda calculus in Python

Lambda Exploring basic lambda calculus in Python. In this repo I have used the lambda function built into python to get a more intiutive feel of lambd

Bhardwaj Bhaskar 2 Nov 12, 2021
This repository contains Python games that I've worked on. You'll learn how to create python games with AI. I try to focus on creating board games without GUI in Jupyter-notebook.

92_Python_Games 🎮 Introduction 👋 This repository contains Python games that I've worked on. You'll learn how to create python games with AI. I try t

Milaan Parmar / Милан пармар / _米兰 帕尔马 166 Jan 01, 2023
Python solution of advent-of-code 2021

Advent of code 2021 Python solutions of Advent of Code 2021 written by Eric Bouteillon Requirements The solutions were developed and tested using Pyth

Eric Bouteillon 3 Oct 25, 2022
Process RunGap output file of a workout and load data into Apple Numbers Spreadsheet and my website with API calls

BSD 3-Clause License Copyright (c) 2020, Mike Bromberek All rights reserved. ProcessWorkout Exercise data is exported in JSON format to iCloud using

Mike Bromberek 1 Jan 03, 2022
A simple but complete exercise to learning Python

ResourceReservationProject This is a simple but complete exercise to learning Python. Task and flow chart We are going to do a new fork of the existin

2 Nov 14, 2022
The git for the Python Story Utility Package library.

PSUP, The Python Story Utility Package Module. PSUP helps making stories or games with options, diverging paths, different endings and so on. You can

Enoki 6 Nov 27, 2022
Easytile blender - Simple Blender 2.83 addon for tiling meshes easily

easytile_blender Dead simple, barebones Blender (2.83) addon for placing meshes as tiles. Installation In Blender, go to Edit Preferences Add-ons

Sam Gibson 6 Jul 19, 2022
Welcome to my pod transcript search webb app!

pod_transcript_search Welcome to the pod transcript search webb app! Tech stack used: Languages used: Python (for the back-end), JavaScript (for the f

3 Feb 04, 2022
Possible solutions to Wordscapes, a mobile game for the android operating system, downloadable from the play store

Possible solutions to Wordscapes, a mobile game for the android operating system, downloadable from the play store

Clifford Onyonka 2 Feb 23, 2022
Solutions to the language assignment for Internship in JALA Technologies.

Python Assignment Solutions (JALA Technologies) Solutions to the language assignment for Internship in JALA Technologies. Features Properly formatted

Samyak Jain 2 Jan 17, 2022
VHDL to Discrete Logic on PCB Flow

PCBFlow Highly experimental set of scripts to transform a digital circuit described in a hardware description language (VHDL or Verilog) into a discre

Tim 77 Nov 04, 2022
PyLaboratory 0 Feb 07, 2022
:fishing_pole_and_fish: List of `pre-commit` hooks to ensure the quality of your `dbt` projects.

pre-commit-dbt List of pre-commit hooks to ensure the quality of your dbt projects. BETA NOTICE: This tool is still BETA and may have some bugs, so pl

Offbi 262 Nov 25, 2022
Python Monopoly Simulator

Monopoly simulator Original creator: Games Computer Play YouTube: https://www.youtube.com/channel/UCTrp88f-QJ1SqKX8o5IDhWQ Config file (optional) conf

Games Computers Play 37 Jan 03, 2023
[Cython] Vs [Python] Which one is Faster ?

[Cython] Vs [Python] ? Attractive Contrast :) Mission : Which one is Faster ? Comparing of Execution runtime for [Selection_sort] with Time Complexity

baqer marani 1 Dec 05, 2021