fspv / leetcode-anki

Anki cards generator for Leetcode
MIT License
297 stars 44 forks source link

too confusing to use #24

Closed ChocoTonic closed 2 years ago

ChocoTonic commented 2 years ago

can you make more documentation on how to actually use this?

fspv commented 2 years ago

Hi @ChocoTonic!

Thanks for your feedback, but can you actually give more details on what exactly is missing?

I tried to use the existing guide https://github.com/prius/leetcode-anki#installation

And it worked without modifications

spv@laptop test $ git clone git@github.com:prius/leetcode-anki.git
Cloning into 'leetcode-anki'...
remote: Enumerating objects: 234, done.
remote: Counting objects: 100% (234/234), done.
remote: Compressing objects: 100% (164/164), done.
remote: Total 234 (delta 110), reused 150 (delta 52), pack-reused 0
Receiving objects: 100% (234/234), 54.61 KiB | 319.00 KiB/s, done.
Resolving deltas: 100% (110/110), done.
spv@laptop test $ cd leetcode-anki/
spv@laptop leetcode-anki $ virtualenv -p python3 leetcode-anki
created virtual environment CPython3.8.10.final.0-64 in 105ms
  creator CPython3Posix(dest=/tmp/test/leetcode-anki/leetcode-anki, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/spv/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
spv@laptop leetcode-anki $ . leetcode-anki/bin/activate
spv@laptop [venv:leetcode-anki] leetcode-anki $ export LEETCODE_SESSION_ID="xxx"
spv@laptop [venv:leetcode-anki] leetcode-anki $ make generate
# You have to set the variables below in order to
# authenticate on leetcode. It is required to read
# the information about the problems
test ! "x/tmp/test/leetcode-anki/leetcode-anki" = "x" || (echo "Need to run inside venv" && exit 1)
pip install -r requirements.txt
Requirement already satisfied: python-leetcode==1.2.1 in ./leetcode-anki/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (1.2.1)
Requirement already satisfied: setuptools==57.5.0 in ./leetcode-anki/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (57.5.0)
Requirement already satisfied: genanki in ./leetcode-anki/lib/python3.8/site-packages (from -r requirements.txt (line 3)) (0.13.0)
Requirement already satisfied: tqdm in ./leetcode-anki/lib/python3.8/site-packages (from -r requirements.txt (line 4)) (4.63.0)
Requirement already satisfied: python-dateutil in ./leetcode-anki/lib/python3.8/site-packages (from python-leetcode==1.2.1->-r requirements.txt (line 1)) (2.8.2)
Requirement already satisfied: six>=1.10 in ./leetcode-anki/lib/python3.8/site-packages (from python-leetcode==1.2.1->-r requirements.txt (line 1)) (1.16.0)
Requirement already satisfied: certifi in ./leetcode-anki/lib/python3.8/site-packages (from python-leetcode==1.2.1->-r requirements.txt (line 1)) (2021.10.8)
Requirement already satisfied: requests in ./leetcode-anki/lib/python3.8/site-packages (from python-leetcode==1.2.1->-r requirements.txt (line 1)) (2.27.1)
Requirement already satisfied: urllib3>=1.15 in ./leetcode-anki/lib/python3.8/site-packages (from python-leetcode==1.2.1->-r requirements.txt (line 1)) (1.26.9)
Requirement already satisfied: frozendict in ./leetcode-anki/lib/python3.8/site-packages (from genanki->-r requirements.txt (line 3)) (2.3.0)
Requirement already satisfied: chevron in ./leetcode-anki/lib/python3.8/site-packages (from genanki->-r requirements.txt (line 3)) (0.14.0)
Requirement already satisfied: cached-property in ./leetcode-anki/lib/python3.8/site-packages (from genanki->-r requirements.txt (line 3)) (1.5.2)
Requirement already satisfied: pyyaml in ./leetcode-anki/lib/python3.8/site-packages (from genanki->-r requirements.txt (line 3)) (6.0)
Requirement already satisfied: idna<4,>=2.5; python_version >= "3" in ./leetcode-anki/lib/python3.8/site-packages (from requests->python-leetcode==1.2.1->-r requirements.txt (line 1)) (3.3)
Requirement already satisfied: charset-normalizer~=2.0.0; python_version >= "3" in ./leetcode-anki/lib/python3.8/site-packages (from requests->python-leetcode==1.2.1->-r requirements.txt (line 1)) (2.0.12)
python3 generate.py
INFO:root:Fetching 2214 problems 2214 per page
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2214/2214 [00:28<00:00, 78.79problem/s]
INFO:root:Generating flashcards
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2213/2213 [00:00<00:00, 25723.16flashcard/s]
spv@laptop [venv:leetcode-anki] leetcode-anki $ ls -lah leetcode.apkg 
-rw-rw-r-- 1 spv spv 6.4M Mar 21 19:23 leetcode.apkg

The only problem is that sometimes leetcode API returns a 503 error (service unreachable), but this is not related to this application, you have to just retry.

ChocoTonic commented 2 years ago

your response was perfect and I got it working on my Linux machine. You should include what you have up there in your installation instructions

it would have been helpful to know what OS this was made for.

I also noticed that the frequency field is broken and will always show 0 for every question.

I was also wondering if there is per question company data available since it's available in the Visual Studio Code leetcode extension for free or the information was scraped from a premium account

SenseCode commented 2 years ago

I am using windows system, and after git clone and set up the environment using the following commands, I am stuck on the export session Id, I don't know what I should input for a leetcode_session_id...

virtualenv -p python3 leetcode-anki
cd leetcode-anki
leetcode-anki\Scripts\activate 
fspv commented 2 years ago

I see. I obviously didn't test it for Windows. I have no idea if environment variables there exist. I will test this evening. If they don't then the cookie can be passed via arguments to the script, which is not implemented yet.

SenseCode commented 2 years ago

I see. I obviously didn't test it for Windows. I have no idea if environment variables there exist. I will test this evening. If they don't then the cookie can be passed via arguments to the script, which is not implemented yet.

Thanks, looking forward to your testing in windows and updated document !

fspv commented 2 years ago

I have added a bit more documentation https://github.com/prius/leetcode-anki/commit/d3a141c3f24441dc473df40bf468cc60fe90c092

With regards to running it on Windows, I spent 40 minutes trying to figure out how to install git, virtualenv, and other stuff there without much luck. My Windows programming knowledge is very limited, so I stopped at this point, as I can't invest so much time into that. If somebody is willing to help with the steps to get it working on Windows, I definitely wouldn't mind.

I found that in order to set an environment variable on Windows you need to use SET or SETX commands instead of export, but didn't test it myself.

SenseCode commented 2 years ago

Thanks, currently hard to make it work. Will test other time to see.

ChocoTonic commented 2 years ago

I spent half an hour trying to get it to work on Windows and gave up. not worth the effort to try to get it to work there when it works easily on Linux

xnorpx commented 2 years ago

@prius thanks for a great project

I did this to get it running on Windows

I had git and python 3.8+ already installed.

git clone https://github.com/prius/leetcode-anki cd leetcode-anki set LEETCODE_SESSION_ID="yyy" python -m venv leetcode-anki .\leetcode-anki\Scripts\activate.bat pip install -r requirements.txt python generate.py

fspv commented 2 years ago

Hi @xnorpx! Thank you so much for working on that and sharing this. I extended the README based on your comment https://github.com/prius/leetcode-anki/pull/29